~/talk

Python Unit Testing with Pytest and Mock

Talkat PyCon US 2021 · 2021-05-14..05-15· [testing, python]
name:Moshe Z
links:none on file
slides:none on file

Step‑by‑step tutorial that actually runs Pytest and mock examples inside Jupyter via ipytest inside Jupyter showing concrete failing assertions (early exercises produce two failed tests), how pytest rewrites assert output, and how mock behaves: naming mocks, setting attributes and deep configure_mock, using return_value and side_effect sequences to make reads/sockets deterministic. Builds tiny buggy functions and a flaky socket parser, then fixes them so tests reliably fail on the bug and pass when fixed.

AI-written summary · about

  1. 0:00Start
  2. 2:06Running Tests
  3. 9:01Example Test
  4. 10:16Assert Statement
  5. 12:15Running the Running Output
  6. 12:41Failure Details
  7. 12:53Test Failure Details
  8. 13:44Failure Summary
  9. 18:55Compare Lists with Lists
  10. 21:15Partial Diffs
  11. 28:28Comparison Operators in Python Test Chain
  12. 29:53Exercise
  13. 56:01Running the Tests
  14. 1:00:33Call a Mock
  15. 1:03:10Magic Mock
  16. 1:08:46Name Your Test
  17. 1:10:20Set the Attribute in the Constructor
  18. 1:27:12Break Time
  19. 1:50:54Call Logs and Call Args
  20. 1:55:34Install Httpx
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.