Using Fixtures for Setup and Teardown
Most of the tests in the Tasks project will assume that the Tasks database is already set up and running and ready. And we should clean things up at the end if there is any cleanup needed. And maybe also disconnect from the database. Luckily, most of this is taken care of within the tasks code with tasks.start_tasks_db(<directory to store db>, ’tiny’ or ’mongo’) and tasks.stop_tasks_db(); we just need to call them at the right time, and we need a temporary directory.
Fortunately, pytest includes a cool fixture called tmpdir that we can use for testing and don’t have to worry about cleaning up. It’s not magic, just good coding by the pytest folks. (Don’t worry; we look at tmpdir and it’s session-scoped relative ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access