-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Document that with pytest.warns()
captures all warnings, not just those it tests were emitted
#9288
Comments
pytest.warns
hides non-expected warnings, even DeprecationWarning
pytest.warns
hides not expected warnings, even DeprecationWarning
Hi @Kojoley, This is the expected behavior, We might add a note to https://docs.pytest.org/en/6.2.x/warnings.html#deprecationwarning-and-pendingdeprecationwarning to mention that behavior does not apply for code inside |
The |
True, thanks!
Hmm I can't think of anything right now, |
Created #9291 to track the docs change. |
If I understand correctly Also, https://docs.pytest.org/en/6.2.x/warnings.html#warns says def test_raises():
with pytest.raises(RuntimeError): # passes,
with pytest.raises(NotImplementedError): # because this will not catch and hide the exception
raise RuntimeError("some exception") |
Yes. 👍
Good point, we need to mention that difference in the docs too. |
pytest.warns
hides not expected warnings, even DeprecationWarning
with pytest.warns()
captures all warnings, not just those it tests were emitted
Alternatively we could make |
I think it would make sense to re-raise all unmatched warnings. For example, say you are testing your own deprecated code so you add |
Note that this also means that if you pass an incorrect value to |
As of #10937, expected in Pytest 8.0, we re-emit all non-matching warnings. |
Fix `tests/test_validators.py::test_root_validator_allow_reuse_same_field` to assert for both warnings emitted, including the Pydantic V1 deprecation warning. Starting with pytest 8.0.0 (thanks to the fix for pytest-dev/pytest#9288), `pytest.warns()` re-emits warnings that weren't caught by the assertion, effectively causing the default run with `-Werror` to fail.
Fix compatibility with pytest==8. Relevant upstream change: pytest-dev/pytest#9288 Fixes #2427
I have a test that ensures a specific warning type is produced by a function, but since I switched to
pytest.warns
I no longer see Python 3.10 compatibility warnings in Pytestwarnings summary
the code was emitting before switching topytest.warns
. Is it expected behavior (in which case it contradicts https://docs.pytest.org/en/6.2.x/warnings.html#deprecationwarning-and-pendingdeprecationwarning) and how I can opt-out of hidingDeprecationWarning
s bypytest.warns
(there is nothing about that in the documentation https://docs.pytest.org/en/6.2.x/reference.html#pytest-warns)?MVCE:
The text was updated successfully, but these errors were encountered: