-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[prerelease] pytest.warns() doesn't seem to work properly for coverage.py #9386
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
Comments
Ah, this is an intentional change to avoid the case where with warnings.catch_warnings():
warnings.simplefilter("ignore") |
Ah, makes sense! I guess in @nedbat's scenario indeed the warning is "optional". So I suppose we can close this one as a duplicate then? |
I wanted to assert that no warnings were raised. Why would I add an ignore filter to do that? Maybe I'm not understanding... |
(I assumed based on the "so we don't see..." comment, thinking that was library rather than test code, and forgetting to wonder why pytest would be there then.) |
It seems a shame to have lost a compact notation for "I assert this won't have any warnings"... |
We never actually had that though! Before, it would pass for any or no warnings, which would be useless if it wasn't also misleading. I agree that a concise notation for this would be good, and propose a new context manager |
I'd happily give a go at this over the holidays! |
I see! I was definitely misunderstanding it then. If a new context manager isn't available in 7.0, I can write one of my own for my test suite. Thanks. |
@olgarithms thanks for the interest in contributing! However before tackling this, I suggest opening a new issue to discuss it. |
…ngs`. The use of `pytest.warns(None)` is deprecated in pytest 7.0.0. The alternative suggested by the deprecation warning, `pytest.warns()`, does not match the old behavior. In fact, `pytest.warns()` is intended specifically to raise an error if the code in the context does not raise the given warning, and in pytest 7.0.0rc1, the default warning used by `pytest.warns()` is the generic `Warning` class. This issue is discussed in the following pytest issues: * pytest-dev/pytest#9002 * pytest-dev/pytest#9386 There, the recommended alternative is to use `warnings.catch_warnings`. That is the change made here. Closes scipygh-15186
Please see #9404. |
…ngs`. The use of `pytest.warns(None)` is deprecated in pytest 7.0.0. The alternative suggested by the deprecation warning, `pytest.warns()`, does not match the old behavior. In fact, `pytest.warns()` is intended specifically to raise an error if the code in the context does not raise the given warning, and in pytest 7.0.0rc1, the default warning used by `pytest.warns()` is the generic `Warning` class. This issue is discussed in the following pytest issues: * pytest-dev/pytest#9002 * pytest-dev/pytest#9386 There, the recommended alternative is to use `warnings.catch_warnings`. That is the change made here. Closes scipygh-15186
From @nedbat via Twitter:
No idea off-hand what's going on there, as that seems exactly what we did in #8677 too.
cc @Zac-HD @olgarithms
The text was updated successfully, but these errors were encountered: