~/talk

Intro to Mocking: Why Unit Testing Doesn't Have To Be So Hard

Talkat DjangoCon US 2015 · 2015-09-06..09-11· [testing]
links:none on file
slides:none on file

Shows concrete claims and working code: mocking removes dependencies, makes nondeterministic code deterministic, verifies calls with no return value, and generates exceptions on demand. Uses Python’s built‑in mock/magicmock with patch and patch.object, demonstrates side_effect and return_value to control randomness and raise errors, and uses assert_called_once_with and call_args_list to verify behavior. Examples include a Tinder‑like “docker” picker and a Stripe charge test; fixes flakiness and speeds tests while noting Django/database tradeoffs.

AI-written summary · about

  1. 0:00Introduction
  2. 0:52Unit Testing
  3. 4:07Problems Mocks Help Solve
  4. 8:01Sample Problem
  5. 15:26Behavior Verification
  6. 17:46Parameter Verification
  7. 21:12Kitten Break
  8. 23:31Why Mocking Doesnt Work
  9. 24:52The Better Way
  10. 25:54Summary
  11. 31:19Mocking Tips
  12. 33:16Create AutoSpec
  13. 33:48Practice TDD
  14. 35:15Avoiding brittle tests
~/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.