Python Unit Testing with Pytest and Mock
summary
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
chapters (20)
- 0:00Start
- 2:06Running Tests
- 9:01Example Test
- 10:16Assert Statement
- 12:15Running the Running Output
- 12:41Failure Details
- 12:53Test Failure Details
- 13:44Failure Summary
- 18:55Compare Lists with Lists
- 21:15Partial Diffs
- 28:28Comparison Operators in Python Test Chain
- 29:53Exercise
- 56:01Running the Tests
- 1:00:33Call a Mock
- 1:03:10Magic Mock
- 1:08:46Name Your Test
- 1:10:20Set the Attribute in the Constructor
- 1:27:12Break Time
- 1:50:54Call Logs and Call Args
- 1:55:34Install Httpx
related talks
49mFor those about to Mock I salute you!
26mUnit Testing Jupyter Notebooks - testbook
33mUnit Testing with Pytest
26mMocking: virtual reality for your Python tests
39mIntro to Mocking: Why Unit Testing Doesn't Have To Be So Hard
24mTesting Your Python Code
32mMock It Till You Make It: How to Verify Your External Mocks Without Ever...
29mUnit testing in the real world with mock
