Record and show contexts when using coverage

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.
This commit is contained in:
Sławek Ehlert 2024-05-02 15:16:32 +02:00
parent a94ef3351e
commit 84bc7c6f90
2 changed files with 2 additions and 2 deletions

View File

@ -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",

View File

@ -6,4 +6,4 @@ set -x
bash scripts/test.sh ${@}
coverage combine
coverage report --show-missing
coverage html
coverage html --show-contexts