Strategies for Testing Async Code in Python

  • asyncio.get_event_loop() returns the current event loop. If there is no current event loop set in the current OS thread, a new event loop will be created and returned.
  • asyncio.new_event_loop() creates and returns a new event loop.

Example Asyncio Use Case: Herding Cats

Challenge: How to Test a Coroutine

Challenge: How to Mock a Coroutine

Challenge: How to Mock an Async Context Manager

--

--

--

Agari is the Trusted Email Identity Company™, protecting companies and people from phishing and socially-engineered email attacks.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Blog Post 307

SubQuery’s Hero Course

Making IT Teams More Effective at Project Management

Making Enemy Shoot when behind Player

Litentry this week: Identity linking and VC milestones; MCP 2.0

Exploring Web Automation with Dynamic Code

What I Learned After Interning as a Full-Stack Developer

My Journey into Tech

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Agari

Agari

Agari is the Trusted Email Identity Company™, protecting companies and people from phishing and socially-engineered email attacks.

More from Medium

Python multithreading for Java Programmers

Python Unit Testing

Docker Series Part 2

Practical docker