⚙️ Record and show test coverage contexts (what test covers which line)#11518
⚙️ Record and show test coverage contexts (what test covers which line)#11518tiangolo merged 3 commits intofastapi:masterfrom slafs:measure-and-show-contexts-in-coverage
Conversation
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.
| "tests", | ||
| "fastapi" | ||
| ] | ||
| context = '${CONTEXT}' |
There was a problem hiding this comment.
Ah, not sure what this piece was for TBH 😅. Decided to remove it though.
There was a problem hiding this comment.
This env var is used by/with GitHub Actions so that coverage can know where to store the coverage files, that way they can be combined later. So I think doing this trick wouldn't work. 🤔
|
📝 Docs preview for commit 84bc7c6 at: https://1ba1b8ae.fastapitiangolo.pages.dev |
|
📝 Docs preview for commit 4d91bb0 at: https://7c1f359a.fastapitiangolo.pages.dev |
|
I was checking the docs, and it seems both contexts can be combined, so we can know which Python version and which tests ran each function. 🎉 🚀 https://coverage.readthedocs.io/en/7.6.1/contexts.html#dynamic-contexts I updated that bit to get that. 🤓 Thank you for your contribution! 🍰 |
…e) (fastapi#11518) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
…e) (fastapi#11518) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
…e) (fastapi#11518) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
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.