Given this, assert that: fluent testing using fixtures and properties
summary
Converts Django API tests into composable pytest fixtures so setup moves out of tests into reusable units (client, user, widget) and fixtures can include teardown and mocks; adding a Hypothesis given decorator plus a widget strategy turns one example into ~100 generated examples that check properties like preserved length and item inclusion; replacing Django test runner with pytest takes about 30 minutes in practice; result is smaller, more focused tests even if overall test count and lines sometimes increase.
AI-written summary · about
chapters (9)
- 0:00Start
- 1:07Reducing boilerplate using pytest fixtures
- 3:00Real world example Testing API methods
- 4:48AAA Pattern: Arrange, act, assert
- 5:30Converting to pytest
- 7:27Lessons from converting an entire codebase
- 10:36Property-based testing
- 12:32A real world example
- 17:55propositional calculus
related talks
27mHypothesis: Simpler Powerful Test Cases
35mTurning test writing into a consistently brief and pleasant experience
21mDon't just test, my friend, test better
20mClimbing Out of Fixture Hell, Indirectly
29mSecrets of the testing masters
28mEgad! How Do We Start Writing Better Tests?
29mAdopt-a-pytest
32mEasy, Breezy, Beautiful... Django Unit Tests with Colleen Dunlap
