Pytest fixtures and cleanup
Fresh state for every test
A fixture is a function pytest calls for each test that names it as a parameter. A function-scoped fixture builds a new value every time, so one test cannot leave a record behind for the next. Put the setup in the fixture instead of a list at module scope, and assert both the starting state and the state after the test changes it.
Cleanup that survives a failure
When the fixture owns a resource, yield it: the code after yield runs as teardown, even when an assertion fails. tmp_path gives each test its own directory. The pytest fixture guide covers scopes and factories. In these exercises you write the tests yourself. The checker runs them against a correct module and two faulty ones, and your module only counts when an assertion catches each fault. A skipped test or a setup error does not count.