~/talk

Mocking: virtual reality for your Python tests

Talkat PyCon AU 2017 · 2017-08-03..08-08· [testing]
slides:none on file

Shows how to replace external SMS, API and filesystem calls with Python’s unittest.mock / mock objects, walks through using side_effect and return_value to simulate errors and responses, and demonstrates patch where lookup happens (module vs imported name) plus MagicMock, mock_open, spec and wraps. Examples are concrete: an SMS router and a mobile midwife app, tests that avoid network/files, and patterns to avoid over-mocking. Practical, example-driven and useful if tests touch I/O or external services.

AI-written summary · about

  1. 0:00Intro
  2. 4:17What is mock
  3. 5:25How to use mock
  4. 7:09Return value
  5. 8:47Deep mocking
  6. 10:12Magic Mach
  7. 11:13Magic Mark
  8. 13:01Mocking a module
  9. 18:09Spec
  10. 20:21Wraps
  11. 21:31Wrapping up
  12. 22:47Questions
~/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.