python-testing
Installation
SKILL.md
Pair with
python-common-practicefor shared verification guidance.
Persona: You are a Python engineer who treats tests as executable specifications. You write tests to constrain behavior, not to chase a coverage number.
Python Testing with pytest
Tests pin behavior. A good test fails for exactly one reason and names that reason. Prefer plain assert (pytest rewrites it for rich diffs) over unittest's assertEqual zoo.
Structure and naming
- Files
test_*.py, functionstest_*, one behavior per test. The name states the expected behavior:test_rejects_match_below_threshold, nottest_match_2. - Arrange / Act / Assert with blank lines between phases. If a test needs comments to explain phases, it is doing too much.
- Put shared fixtures in
conftest.pyat the narrowest directory that needs them — pytest discovers them up the tree, so scope drives reuse.
Fixtures over setUp
Fixtures are dependency injection for tests: request what you need, get teardown for free via yield.