Skip to content

Commit a80d0ad

Browse files
committed
PYTHON-5753 Add just recipes for running coverage tests locally
1 parent 3d89d9f commit a80d0ad

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ the pages will re-render and the browser will automatically refresh.
205205
and the `<class_name>` to test a full module. For example:
206206
`just test test/test_change_stream.py::TestUnifiedChangeStreamsErrors::test_change_stream_errors_on_ElectionInProgress`.
207207
- Use the `-k` argument to select tests by pattern.
208+
- Run `just test-coverage` to run tests with coverage and display a report. Use `just coverage-html` to generate an HTML report in `htmlcov/index.html`.
208209

209210

210211
## Running tests that require secrets, services, or other configuration

justfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,35 @@ teardown-tests:
8282
integration-tests:
8383
bash integration_tests/run.sh
8484

85+
[group('test')]
86+
test-coverage *args="":
87+
#!/usr/bin/env bash
88+
set -euo pipefail
89+
if [ -n "${USE_ACTIVE_VENV:-}" ]; then
90+
# When USE_ACTIVE_VENV is set, run coverage directly in the active venv
91+
uv run --active --extra test --group coverage python -m coverage run -m pytest {{args}}
92+
uv run --active --group coverage python -m coverage report
93+
else
94+
# Otherwise use the standard Evergreen workflow
95+
just setup-tests --cov
96+
just run-tests {{args}}
97+
just coverage-report
98+
fi
99+
100+
[group('coverage')]
101+
coverage-report:
102+
uv tool run --with "coverage[toml]" coverage report
103+
104+
[group('coverage')]
105+
coverage-html:
106+
uv tool run --with "coverage[toml]" coverage html
107+
@echo "Coverage report generated in htmlcov/index.html"
108+
109+
[group('coverage')]
110+
coverage-xml:
111+
uv tool run --with "coverage[toml]" coverage xml
112+
@echo "Coverage report generated in coverage.xml"
113+
85114
[group('server')]
86115
run-server *args="":
87116
bash .evergreen/scripts/run-server.sh {{args}}

0 commit comments

Comments
 (0)