-
Notifications
You must be signed in to change notification settings - Fork 213
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
Warnings misuse #675
Labels
Comments
webknjaz
added a commit
to webknjaz/antonbabenko--pre-commit-terraform
that referenced
this issue
Jan 30, 2025
This is emitted by `pytest-cov` [[1]] and is turned into an error by the default `-Werror` passed to Python, not the `filterwarnings` setting within the `pytest`. The patch selectively suppresses the warning so there's nothing to turn into an error in the first place. Insufficient coverage still marks the test session as failed as it's supposed to. [1]: pytest-dev/pytest-cov#675
MaxymVlasov
pushed a commit
to antonbabenko/pre-commit-terraform
that referenced
this issue
Jan 30, 2025
This is emitted by `pytest-cov` [[1]] and is turned into an error by the default `-Werror` passed to Python, not the `filterwarnings` setting within the `pytest`. The patch selectively suppresses the warning so there's nothing to turn into an error in the first place. Insufficient coverage still marks the test session as failed as it's supposed to. [1]: pytest-dev/pytest-cov#675
webknjaz
added a commit
to webknjaz/ansible--awx-plugins
that referenced
this issue
Feb 6, 2025
This is emitted by `pytest-cov` [[1]] and is turned into an error by the default `-Werror` passed to Python, not the `filterwarnings` setting within the `pytest`. The patch selectively suppresses the warning so there's nothing to turn into an error in the first place. Insufficient coverage still marks the test session as failed as it's supposed to. [1]: pytest-dev/pytest-cov#675
webknjaz
added a commit
to ansible/awx-plugins
that referenced
this issue
Feb 11, 2025
This is emitted by `pytest-cov` [[1]] and is turned into an error by the default `-Werror` passed to Python, not the `filterwarnings` setting within the `pytest`. The patch selectively suppresses the warning so there's nothing to turn into an error in the first place. Insufficient coverage still marks the test session as failed as it's supposed to. [1]: pytest-dev/pytest-cov#675
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
I've faced something that I believe is improper use of the warnings mechanism in Python.
Warnings are supposed to signal about something deprecated or called incorrectly. However, I see that it's being used to duplicate the reported information during regular operation (emitting a warning in addition to printing out the same and setting the test session outcome).
So in this instance, the end-user uses
pytest-cov
correctly, but still gets warnings.I tend to surface warnings as errors so they're caught early, which causes it to show up as an internal pytest error. I'm convinced this shouldn't be happening.
Expected vs actual result
When I'm running
python -Werror -Im pytest -- some/test.py
, while havingfail_under = 100
, this causes a traceback.Since it just runs a subset of tests, it's expected that coverage wouldn't be at 100%. And I'd expect it to mark the test session as failed.
What I didn't expect, though, was that it additionally issues a warning, which
-Werror
turns into an error resulting in a traceback being printed out.Reproducer
Versions
Config
The
covdefaults
plugin of coveragepy setsfail_under = 100
Code
This is the repo version without the workaround: https://github.com/antonbabenko/pre-commit-terraform/tree/4b0ad90
tox -qq -- tests/pytest/_cli_test.py::test_app_exit -qq
will do:A workaround is to pass
-W 'ignore:Coverage failure::pytest_cov.plugin'
but it's rather a hack.The text was updated successfully, but these errors were encountered: