How to Run Pytest Tests with Coverage for ADR Sensor Development
Use pytest tests/ -v --cov=adr_sensor from the Sensor/ directory to execute the test suite with coverage reporting, or run uv run pytest -q for a streamlined CI-style output.
The ADR repository from Uber provides a complete testing setup for its sensor component. Learning how to run pytest tests with coverage for ADR Sensor development ensures your contributions meet quality standards and maintain reproducibility across environments.
Prerequisites: Development Dependencies
The sensor package declares its testing stack in Sensor/pyproject.toml. The [project.optional-dependencies] section pins pytest ≥ 7.0.0 and pytest-cov ≥ 4.1.0 as dev extras【/cache/repos/github.com/uber/ADR/main/Sensor/pyproject.toml#L31-L35】.
Install these dependencies using the repository's uv package manager:
cd Sensor
uv sync --dev
This command reads the uv.lock file to reproduce the exact environment, including ruff for linting alongside the testing tools.
Running Tests: Two Entry Points
Direct Pytest Invocation
Execute tests from the Sensor/ directory with standard pytest commands:
# Detailed output for debugging
pytest tests/ -v
# Quiet mode for CI pipelines
pytest tests/ -q
The default test location is configured in pyproject.toml under tool.pytest.ini_options, so pytest discovers tests in the tests/ folder automatically.
UV Wrapper Command
For reproducible environments without manual activation:
uv run pytest -q
This approach ensures the locked dependency versions are always used, matching the workflow described in the project's reproducibility documentation【/cache/repos/github.com/uber/ADR/main/docs/REPRODUCIBILITY.md#L47-L52】.
Measuring Code Coverage
Add pytest-cov flags to any test command to measure line coverage for the adr_sensor package source code located at Sensor/adr_sensor/.
Console Coverage Report
pytest tests/ -v --cov=adr_sensor
Outputs coverage percentages directly in your terminal after test completion.
HTML Coverage Report
pytest tests/ -v --cov=adr_sensor --cov-report=html
Generates a browsable report at htmlcov/index.html. View it with:
open htmlcov/index.html # macOS
xdg-open htmlcov/index.html # Linux
The HTML report highlights uncovered lines in modules like adr_sensor/observer.py, helping you identify gaps in test coverage for the core orchestrator class.
Complete Development Workflow
Follow this sequence when contributing to ADR Sensor:
-
Sync environment
cd Sensor uv sync --dev -
Run tests during development
uv run pytest -q -
Validate with coverage before submitting
pytest tests/ -v --cov=adr_sensor --cov-report=html -
Review coverage gaps in
htmlcov/index.htmland add tests for uncovered logic inSensor/tests/modules liketest_utils.pyortest_schemas.py.
These commands match the official instructions in the Sensor README【/cache/repos/github.com/uber/ADR/main/Sensor/README.md#L227-L230】.
Key Configuration Files
| File | Purpose |
|---|---|
Sensor/pyproject.toml |
Declares dev dependencies and tool.pytest.ini_options |
Sensor/uv.lock |
Pins exact versions of pytest, pytest-cov, and other tools |
Sensor/tests/ |
Unit tests for parsers, schemas, and observer logic |
docs/REPRODUCIBILITY.md |
CI-focused test commands for automated runs |
Summary
- Install:
uv sync --devinSensor/directory pulls pytest and pytest-cov - Run tests:
pytest tests/ -voruv run pytest -q - Add coverage: Append
--cov=adr_sensorto measure package coverage - Generate reports: Use
--cov-report=htmlfor detailed HTML output - Verify locally: Check
htmlcov/index.htmlbefore submitting changes
Frequently Asked Questions
What Python versions does ADR Sensor support for testing?
The pyproject.toml specifies Python version constraints that pytest inherits. Check the requires-python field in Sensor/pyproject.toml for the supported range. The uv.lock file ensures tested versions are reproducible across machines.
Why does coverage report zero percent for some modules?
Files in adr_sensor/ that are never imported during test execution show zero coverage. Expand your test suite in Sensor/tests/ to exercise modules like observer.py or add __init__.py coverage by importing package-level constants in test files.
Can I run a single test file instead of the full suite?
Yes. Specify the path directly: pytest tests/test_schemas.py -v --cov=adr_sensor. Pytest's test discovery still applies coverage measurement only to the executed code paths.
How do I integrate this with GitHub Actions CI?
The same commands work in CI. Use uv run pytest -q --cov=adr_sensor for concise logs, and add --cov-report=xml to generate Cobertura-compatible output for coverage tracking services. The repository's reproducibility guide documents this pattern for automated runs without external API dependencies【/cache/repos/github.com/uber/ADR/main/docs/REPRODUCIBILITY.md#L47-L52】.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →