Skip to content

Commit

Permalink
Record and show contexts when using coverage
Browse files Browse the repository at this point in the history
As documented in https://coverage.readthedocs.io/en/7.5.0/contexts.html#dynamic-contexts

While working on #11517 I wanted to see which test
is best to modify for the fix.
One way to easily find this out is to see which line is covered
by which test.

This PR adds a dynamic context setting
and makes them show on the HTML coverage report.
The contexts are test function names.

NOTE pytest-cov plugin has even better support
for pytest test names as coverage contexts,
but I think this PR is already an imporovement.
  • Loading branch information
slafs committed May 2, 2024
1 parent a94ef33 commit 84bc7c6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ source = [
"tests",
"fastapi"
]
context = '${CONTEXT}'
dynamic_context = "test_function"
omit = [
"docs_src/response_model/tutorial003_04.py",
"docs_src/response_model/tutorial003_04_py310.py",
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-cov-html.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -x
bash scripts/test.sh ${@}
coverage combine
coverage report --show-missing
coverage html
coverage html --show-contexts

0 comments on commit 84bc7c6

Please sign in to comment.