Skip to content

Commit 84bc7c6

Browse files
committed
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.
1 parent a94ef33 commit 84bc7c6

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ source = [
206206
"tests",
207207
"fastapi"
208208
]
209-
context = '${CONTEXT}'
209+
dynamic_context = "test_function"
210210
omit = [
211211
"docs_src/response_model/tutorial003_04.py",
212212
"docs_src/response_model/tutorial003_04_py310.py",

scripts/test-cov-html.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set -x
66
bash scripts/test.sh ${@}
77
coverage combine
88
coverage report --show-missing
9-
coverage html
9+
coverage html --show-contexts

0 commit comments

Comments
 (0)