conftest.py Configuration
The ConftestConfigFile manages the tests/conftest.py file.
Overview
Creates a conftest.py file that:
- Imports pyrig's test fixtures and plugins as a pytest plugin
- Configures pytest for the test suite
- Sets up fixtures and hooks for all test scopes
- Ensures consistent test infrastructure across projects
Inheritance
Inherits from: PythonTestsConfigFile
What this means:
- Python file in the tests directory (
PythonTestsConfigFilesets parent path totests/) - Uses line-based content via
get_lines()(inherited fromStringConfigFile) - Validates by checking if required content exists anywhere in the file
- Allows user additions as long as required
pytest_pluginsimport exists
File Location
Path: tests/conftest.py
Extension: .py - Python source file.
Filename: conftest - Special pytest configuration file.
How It Works
Automatic Generation
When initialized via uv run pyrig mkroot, the file is created with:
- Docstring: Explains the file's purpose as the pyrig pytest plugin
- Plugin import: Imports
pyrig.dev.tests.conftestas a pytest plugin - Pytest integration: Automatically loads pyrig's fixtures and hooks
Generated Content
pytest_plugins = ["pyrig.dev.tests.conftest"]
The pytest_plugins list tells pytest to load pyrig's conftest module, making
all pyrig fixtures available.
Validation Logic
The is_correct() method checks for the required plugin import. The file is
considered valid if it contains the pytest_plugins line with the pyrig
conftest import path.
Required element: The pytest_plugins list with pyrig's conftest import.
Flexible content: You can add additional plugins or configuration as long as the required import exists.
Usage
Automatic Creation
uv run pyrig mkroot
Purpose
This file configures pytest to use pyrig's test infrastructure, including:
- Autouse fixtures (session, package, module, class, function scopes)
- Factory fixtures (
config_file_factory) - Custom pytest hooks and plugins
See the Testing documentation for details on the test infrastructure.
Best Practices
- Don't remove the import: Keep the
pytest_pluginsimport intact - Add custom plugins: You can add additional pytest plugins to the list
- Avoid manual modification: The file is auto-generated and should rarely need changes
- Use fixtures package: Add custom fixtures in
dev/tests/fixtures/instead