Framework Mode - pytest-cov setup
Folder Structure
project-root/ ├── tests/ │ ├── test_example.py │ └── __init__.py ├── src/ │ └── app_code.py ├── .coveragerc ├── pytest.ini ├── requirements.txt └── README.md
project-root/ ├── tests/ │ ├── test_example.py │ └── __init__.py ├── src/ │ └── app_code.py ├── .coveragerc ├── pytest.ini ├── requirements.txt └── README.md
tests/ folder, contains pytest test functions.src/ folder, the code under test.pytest.ini and .coveragerc files configure pytest and coverage behavior.tests/ or a separate tests/utils/ folder.Use pytest.ini to configure pytest options and enable coverage plugin:
[pytest] addopts = --cov=src --cov-report=term-missing
Use .coveragerc to customize coverage settings, for example:
[run]
branch = True
source = src
[report]
exclude_lines =
if __name__ == "__main__":
pragma: no cover
Manage environment variables or credentials using pytest fixtures or external files, keeping secrets out of code.
--cov-report=xml to generate XML reports for CI tools.--cov-fail-under=80.if __name__ == '__main__'.Where would you add a new fixture that sets up a test database connection for coverage-instrumented tests?