diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a4eafeddc..278cf579c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -205,6 +205,7 @@ the pages will re-render and the browser will automatically refresh. and the `` to test a full module. For example: `just test test/test_change_stream.py::TestUnifiedChangeStreamsErrors::test_change_stream_errors_on_ElectionInProgress`. - Use the `-k` argument to select tests by pattern. +- 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`. ## Running tests that require secrets, services, or other configuration diff --git a/justfile b/justfile index 78f48c2c7..a3389d6fb 100644 --- a/justfile +++ b/justfile @@ -82,6 +82,35 @@ teardown-tests: integration-tests: bash integration_tests/run.sh +[group('test')] +test-coverage *args="": + #!/usr/bin/env bash + set -euo pipefail + if [ -n "${USE_ACTIVE_VENV:-}" ]; then + # When USE_ACTIVE_VENV is set, run coverage directly in the active venv + uv run --active --extra test --group coverage python -m coverage run -m pytest {{args}} + uv run --active --group coverage python -m coverage report + else + # Otherwise use the standard Evergreen workflow + just setup-tests --cov + just run-tests {{args}} + just coverage-report + fi + +[group('coverage')] +coverage-report: + uv tool run --with "coverage[toml]" coverage report + +[group('coverage')] +coverage-html: + uv tool run --with "coverage[toml]" coverage html + @echo "Coverage report generated in htmlcov/index.html" + +[group('coverage')] +coverage-xml: + uv tool run --with "coverage[toml]" coverage xml + @echo "Coverage report generated in coverage.xml" + [group('server')] run-server *args="": bash .evergreen/scripts/run-server.sh {{args}}