I'm working on a Python project with FastAPI and Pony ORM. We're creating unit tests for each module of the program, and we want to be able to run all the tests together (there's one test file for each module). However, we have an issue where each test inserts data into the database (using Pony ORM), and since all the other tests assume the database is clean at the start, they fail when executed one after the other.
I wanted to know if it's possible with pytest to create a function that runs after each test module and cleans the database so that each test can work with an empty database and function correctly.
We have all the tests in a directory called "test/." We're all relatively new to this technology, so some things are challenging for us.
I've already tried creating a pytest fixture with scope="module" that performs db.droptables(cleardata=True) and db.generate_mapping, but it didn't yield results.
Create a fixture that cleans the db
you can verify the logs and see the cleaning db message