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

Unittest AsyncMock

Pranay Suresh
February 05, 2020

Unittest AsyncMock

Talk about how to mock async methods in different versions of Python

Pranay Suresh

February 05, 2020
Tweet

More Decks by Pranay Suresh

Other Decks in Technology

Transcript

  1. Unittest AsyncMock
    https://pranaysuresh.com/
    https://www.linkedin.com/in/pranaysuresh/

    View Slide

  2. View Slide

  3. View Slide

  4. Because...

    View Slide

  5. Prior to Python 3.8
    Option 1: Custom solution

    View Slide

  6. Prior to Python 3.8

    View Slide

  7. Prior to Python 3.8
    Option 2: asynctest library: https://pypi.org/project/asynctest/

    View Slide

  8. Python 3.8

    View Slide

  9. View Slide

  10. Other features:
    assert_awaited, assert_awaited_once,
    assert_awaited_with, await_count etc etc.

    View Slide

  11. Other features:
    Mock iterators

    View Slide

  12. Other features:
    Mock context managers

    View Slide

  13. Thank You!

    View Slide