Framework Mode - setup.cfg configuration
Folder Structure
project-root/ ├── tests/ │ ├── test_example.py │ └── conftest.py ├── src/ │ └── app_code.py ├── setup.cfg └── pytest.ini (optional)
project-root/ ├── tests/ │ ├── test_example.py │ └── conftest.py ├── src/ │ └── app_code.py ├── setup.cfg └── pytest.ini (optional)
tests/ folder, contains test scripts like test_example.py.conftest.py holds shared setup code and fixtures.src/ folder, the code under test.setup.cfg file configures pytest options and plugins.The setup.cfg file centralizes pytest settings. It helps to:
Example setup.cfg content:
[tool:pytest]
minversion = 7.0
addopts = -ra -q
testpaths = tests
python_files = test_*.py
markers =
smoke: quick smoke tests
slow: slow running tests
This file lives at the project root and is automatically read by pytest.
Use setup.cfg to configure reporting plugins like pytest-cov and pytest-junitxml.
[tool:pytest] addopts = --cov=src --cov-report=term-missing --junitxml=reports/junit.xml
CI/CD pipelines can run pytest with these settings to generate coverage and XML reports for dashboards.
Reports help teams see test results clearly and catch failures early.
setup.cfg to avoid repeating CLI flags.setup.cfg so all team members share the same test setup.conftest.py: Use setup.cfg for config and conftest.py for fixtures and hooks.Where in this framework structure would you add a new marker called regression to label regression tests?
setup.cfg file in pytest?setup.cfg file is used to keep pytest settings centralized.setup.cfg.setup.cfg?[pytest] and python_files sets test file patterns.python_files = test_*.py matches typical test files.setup.cfg snippet:[pytest] markers = slow: marks tests as slow python_files = test_*.py
pytest -m slow?slow is defined to label slow tests.-m slow optionpytest -m slow runs only tests marked with @pytest.mark.slow.setup.cfg:[pytest] markers = slow: marks slow tests python_files = test_*.py python_classes = Test* python_functions = test_*
legacy_tests folder without typing command line options. How do you configure setup.cfg to do this?--ignore=folder option tells pytest to skip that folder.addopts = --ignore=legacy_tests runs pytest with this option automatically.Pass the test and this pattern moves unknown