Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚙️ Record and show test coverage contexts (what test covers which line) #11518

Merged
merged 3 commits into from
Aug 16, 2024

Conversation

slafs
Copy link
Contributor

@slafs slafs commented May 2, 2024

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.

As documented in https://coverage.readthedocs.io/en/7.5.0/contexts.html#dynamic-contexts

While working on fastapi#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.
@@ -206,7 +206,7 @@ source = [
"tests",
"fastapi"
]
context = '${CONTEXT}'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, not sure what this piece was for TBH 😅. Decided to remove it though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 🤔

@tiangolo
Copy link
Member

tiangolo commented May 2, 2024

📝 Docs preview for commit 84bc7c6 at: https://1ba1b8ae.fastapitiangolo.pages.dev

@tiangolo tiangolo changed the title Record and show contexts when using coverage ⚙️ Record and show test coverage contexts (what test covers which line) Aug 16, 2024
@tiangolo tiangolo removed the p5 label Aug 16, 2024
Copy link
Contributor

📝 Docs preview for commit 4d91bb0 at: https://7c1f359a.fastapitiangolo.pages.dev

@tiangolo
Copy link
Member

tiangolo commented Aug 16, 2024

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! 🍰

@tiangolo tiangolo merged commit 0aaaed5 into fastapi:master Aug 16, 2024
57 checks passed
black-redoc pushed a commit to black-redoc/fastapi that referenced this pull request Aug 16, 2024
black-redoc pushed a commit to black-redoc/fastapi that referenced this pull request Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants