What is conftest.py for in pytest?
Options
- Configuring the linters of the whole project
- Sharing fixtures and hooks with the tests below it (Correct option)
- Storing the test data files of the project
- Defining the CI pipelines of the repository
Answer
Sharing fixtures and hooks with all tests in that directory and below, without importing them
Why
Fixtures defined in a conftest.py file are automatically available to every test in the same folder and its subfolders. You don't import them.
Typical content: database fixtures, a test client for your app, shared fake objects.
General pytest settings go in pyproject.toml or pytest.ini.
Remember
conftest.py = shared fixtures for a folder of tests.