-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
🧪 Unmeasure coverage in tests expected to fail #12531
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
Conversation
These tests are known to only be executed partially or not at all. So we always get incomplete, missing, and sometimes flaky, coverage in the test functions that are expected to fail. This change updates the ``coverage.py`` config to prevent said tests from influencing the coverage level measurement.
FTR this is motivated by my attempt to look into improving the Codecov config. While checking it out, I noticed that there's uncovered lines in tests, meaning that some tests might never run in CI, and we'd never notice. It shouldn't be like that: https://nedbatchelder.com/blog/202008/you_should_include_your_tests_in_coverage.html. I hope, this will help us start requiring 100% coverage on tests, having followed the best practices as outlined in https://adamj.eu/tech/2019/04/30/getting-a-django-application-to-100-percent-coverage/. This won't affect non-testing code for now but seemed like a good place to start. |
I like the idea, however I fear it might over-ignore some stuff. If we don't have too many xfails, I'd feel better with just manual |
@bluetech yeah, I had a feeling that there might not be enough buy-in. However, I believe this will not over-ignore stuff. Yes, there's some coverage on the first lines of some xfail tests, but it's not really useful. Over time, more or less lines may start failing there, and it'll influence PR-reported coverage changes here and there for no reason. It's even worse if the tests are very flaky. It might make sense to measure coverage when working on fixing said xfail tests, but in that situation, one could just as well comment out or remove the mark while debugging. I gave it enough thought over the years to think that there's no case where having coverage collected on any xfailing test is useful. Do you have any example of where this would over-ignore tests? I intentionally wrote the regex in a way that would work with explicit xfail mark decorators applied to all the parametrized variants and not to the cases where this mark is applied to only some parametrize factors. This will also leave out module-level |
For a project which is using pytest, I agree there is little risk. But here we are not only using pytest, we are also developing pytest and testing pytest, and my "over-ignoring" concern is for the latter two. Probably it's not a real issue but it feels like something that might start ignoring some unintended piece of code without us noticing. |
That's the concern I'm trying to minimize here — with random unrelated coverage information changes, people are trained to ignore it altogether and never look into it. Just look into the effect of Codecov having a reputation of being flaky — it's been broken on And I think that this is a low-effort improvement that would enhance the experience greatly. I just can't imagine a situation where we'd want to have xfailing tests non-ignored. Of course, for the lines that we know get always executed, it'd be nice to keep the coverage but then, we'd have to add a Do you have any suggestions on handling things like https://app.codecov.io/gh/pytest-dev/pytest/blob/main/testing%2Ftest_debugging.py#L388? |
@webknjaz OK, I trust you judgment on this. Thanks for improving the coverage situation! |
Just a heads up from me on this -- while I think reaching 100% coverage is a laudable goal, I think that enforcing 100% is somewhat harmful. Sometimes you just want to do something without doing it perfectly... |
I don't think that enforcing it is harmful, as long as you use |
@nicoddemus @RonnyPfannschmidt @The-Compiler do you want to post your opinions here before this is merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the configuration, thanks!
I don't think that enforcing it is harmful, as long as you use # pragma: no cover for all the places you consciously want to skip from being taken into account. Especially, for the tests.
I agree, I have a few projects where this is enforced and indeed it is beneficial, given you can add an explicit ignore when needed. 👍
Backport to 8.2.x: 💚 backport PR created✅ Backport PR branch: Backported as #12551 🤖 @patchback |
Thanks for the feedback, everyone! |
(cherry picked from commit 1a8394e)
report. This has an effect of reducing the influence of flaky | ||
tests on the resulting number. | ||
|
||
-- by :user`webknjaz` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Syntax correction: #12560
It is easy to forget backticks in change note bylines. It's happened in pytest-dev#12531 already, requiring a hotfix in pytest-dev#12560. The pre-commit based check idea is coming from the Tox project and have been battle-tested in aiohttp, CherryPy, and other ecosystems.
It is easy to forget backticks in change note bylines. It's happened in pytest-dev#12531 already, requiring a hotfix in pytest-dev#12560. The pre-commit based check idea is coming from the Tox project and have been battle-tested in aiohttp, CherryPy, and other ecosystems.
These tests are known to only be executed partially or not at all. So we always get incomplete, missing, and sometimes flaky, coverage in the test functions that are expected to fail. This change updates the ``coverage.py`` config to prevent said tests from influencing the coverage level measurement. Ref pytest-dev/pytest#12531
These tests are known to only be executed partially or not at all. So we always get incomplete, missing, and sometimes flaky, coverage in the test functions that are expected to fail. This change updates the ``coverage.py`` config to prevent said tests from influencing the coverage level measurement. Ref pytest-dev/pytest#12531
These tests are known to only be executed partially or not at all. So we always get incomplete, missing, and sometimes flaky, coverage in the test functions that are expected to fail. This change updates the ``coverage.py`` config to prevent said tests from influencing the coverage level measurement. Ref pytest-dev/pytest#12531
These tests are known to only be executed partially or not at all. So we always get incomplete, missing, and sometimes flaky, coverage in the test functions that are expected to fail.
This change updates the
coverage.py
config to prevent said tests from influencing the coverage level measurement.