π§ββοΈ A Letter from Hogwarts
Dear Witch or Wizard Developer,
We are pleased to inform you that you have been accepted at Hogwarts School of Software Sorcery,
Department of Defense Against the Dark Bugs. Your wand is your keyboard, your spellbook is pytest,
and your Patronus is a well-tested codebase.
This course takes you from first-year charms (marks & parametrization) through O.W.L.-level magic
(fixtures, mocking, debugging) and all the way to N.E.W.T. mastery (property-based testing, custom plugins).
By the end, you'll be a fully qualified Wandmaker β crafting your own testing instruments from scratch.
"It does not do to dwell on untested code and forget to live." β Albus Dumbledore, probably.
π Curriculum
-
1The Time-Turner: Marks & Parametrization
Hermione's Time-Turner lets her attend multiple classes at once. Marks and parametrize let your tests run multiple scenarios in a single function.
-
2The Room of Requirement: Fixtures Basics
The Room of Requirement provides exactly what you need, when you need it. Fixtures do the same for your tests β setup, data, and teardown on demand.
-
3The Room of Requirement: Advanced Magic
Deeper into the Room. Scoped fixtures, parametrized fixtures, fixture factories β the advanced transfiguration of test infrastructure.
-
4Ministry-Issued Spells: Built-in Fixtures
The Ministry of Magic provides standard-issue spells to all Aurors. pytest ships powerful built-in fixtures β tmp_path, monkeypatch, capsys, and more.
-
5Riddikulus! Defeating the Boggart of Dependencies
A Boggart takes the shape of your worst fear β an external API, a database, a filesystem. The Riddikulus charm (mocking) transforms it into something manageable.
-
6Lumos! Illuminating Failing Tests
When darkness falls and tests fail mysteriously, cast Lumos. Debugging techniques that shed light on the darkest corners of your code.
-
7Weasleys' Wizard Wheezes: The Plugin Ecosystem
Fred and George's joke shop is packed with ingenious inventions. The pytest plugin ecosystem is just as wild β coverage, xdist, BDD, and hundreds more.
-
8The Imperius Curse: Property-Based Testing with Hypothesis
The Imperius Curse forces its target to do whatever you command. Hypothesis forces your code to handle whatever input the universe throws at it.
-
9Becoming a Wandmaker: Writing Custom Plugins
Ollivander crafts wands tailored to each wizard. In this final lesson, you learn to craft your own pytest plugins β bespoke tools for your unique testing needs.
"Mischief Managed." πΊοΈ
Posted by Giacomo Saccaggi in December, 2023