From 84bc7c6f90dda05fa8c93cbf711623edecfc1764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Ehlert?= Date: Thu, 2 May 2024 15:16:32 +0200 Subject: [PATCH] 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. --- pyproject.toml | 2 +- scripts/test-cov-html.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 05c68841ff..cad91e8b2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/scripts/test-cov-html.sh b/scripts/test-cov-html.sh index d1bdfced2a..85aef96018 100755 --- a/scripts/test-cov-html.sh +++ b/scripts/test-cov-html.sh @@ -6,4 +6,4 @@ set -x bash scripts/test.sh ${@} coverage combine coverage report --show-missing -coverage html +coverage html --show-contexts