Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Neil Chazin - Strategies for testing Async code

Neil Chazin - Strategies for testing Async code

Testing code is important. Testing, primarily unit-testing async code requires heading off the the standard roadway of unit testing in python. This talk will provide a map to help you along the new path towards testing async code.

Topics include:

a brief intro to asyncio and challengs in testing with it
running coroutines (and other awaitables) under test
mocking coroutines
testing "main" asyncio loops


PyCon 2019

May 05, 2019

More Decks by PyCon 2019

Other Decks in Programming


  1. Who am I? — Programming in Python since the early

    2000s — Believe that testing software is important — @neilathotep neil chazin - @neilathotep
  2. Work — Currently Senior Software Engineer/Tech Lead at Agari —

    Agari secures digital communications to ensure humanity prevails over evil neil chazin - @neilathotep
  3. Brief Outline 1. Why? 2. Quick intro to async &

    asyncio 3. Challenges of testing — Some solutions I've found 4. Wrap up neil chazin - @neilathotep
  4. General Async Basics — Concurrency through cooperation — yield control

    when 'waiting' - asynchronous results neil chazin - @neilathotep
  5. asyncio — framework for asynchronous computing — available in stdlib

    as of 3.4 — Improved syntax in 3.5 — Incremental changes in 3.6 and 3.7 neil chazin - @neilathotep
  6. Two primary concepts — Coroutines: perform asynchronous work — Event

    loops: schedule asynchronous work neil chazin - @neilathotep
  7. Key syntax — async - define a coroutine — await

    - 'call' a coroutine neil chazin - @neilathotep
  8. — Previous patterns all work great but some short comings

    I've found: — test coroutines that do not run in the MainThread when executing — test syncronous functions that call into event loops () — functional tests — Event Loop variants (e.g. uvloop) neil chazin - @neilathotep
  9. Wrap up — Try out asyncio programming — Keep testing

    — Find sample code and presentation at: h!ps://bit.ly/nchazin-pycon2019 neil chazin - @neilathotep