Advanced Strategies for Testing Async Code in Python

  • Testing coroutines that are run in event loops outside of the MainThread
  • Testing synchronous functions that call into event loops
  • Functional tests, which might including testing non-terminating coroutines
  • Alternate event loops

More Advanced Strategies

The example above is the final one given in the PyCon US presentation, but there are two bonus examples included in this post. First, there is an example use case that is more complex. The code for this example can be found here. Consider the following simple network server:



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 is the Trusted Email Identity Company™, protecting companies and people from phishing and socially-engineered email attacks.