Anatomy of a generated LeetCode test suite: 10+ parametrized pytest cases per problem, logged output, and one suite covering multiple solutions.
Tests ship with the problem. You never write test scaffolding. You arrive,
run the suite, watch it fail, and make it pass. For the local-setup
workflow (installing pytest, first red-green loop, running single cases),
see Test LeetCode Solutions Locally; this page
is about how the test cases themselves are built.
Each test method is parametrized over 10+ cases: the examples from the
problem statement plus edge cases like empty results, negatives, duplicates,
and boundary sizes.
The run_/assert_ pair from Problem Anatomy
keeps input formatting in one place and normalizes comparison, so a
returned [1, 0] does not fail against expected [0, 1] when order does
not matter.
The @logged_test decorator (from leetcode_py) wraps each test with
loguru output: the case being run, Test passed! ✨ on success, or a full
logger.exception traceback on failure.
Implementing a second approach, say SolutionMath next to Solution?
Don’t copy the tests. Parametrize over the solution class and the same
suite covers every approach: