-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
pytest.warns
and pytest.raises
ordering issue
#9036
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
Labels
plugin: warnings
related to the warnings builtin plugin
type: bug
problem that needs to be addressed
Comments
3 tasks
20 tasks
2 tasks
4 tasks
Cheukting
added a commit
to Cheukting/pytest
that referenced
this issue
Jun 22, 2023
Zac-HD
pushed a commit
to Cheukting/pytest
that referenced
this issue
Jul 1, 2023
JoepVanlier
added a commit
to lumicks/pylake
that referenced
this issue
Jan 30, 2024
pytest changed its warning/exception order (see pytest-dev/pytest#9036). This updates our tests to fit the new spec. For kymographs, this meant explicitly passing a motion blur parameter such that we don't issue that error instead of what we are looking for. For the dwelltime analysis, we have to make sure we don't get any of the deprecation warnings so that we can see the warning we are testing for. For touchdown, we have to explicitly silence the covariance matrix is undefined error (which actually already tells us that the problem will be non-identifiable).
JoepVanlier
added a commit
to lumicks/pylake
that referenced
this issue
Jan 30, 2024
pytest changed its warning/exception order starting from 8.0.0 (see pytest-dev/pytest#9036). This updates our tests to fit the new spec. For kymographs, this meant explicitly passing a motion blur parameter such that we don't issue that error instead of what we are looking for. For the dwelltime analysis, we have to make sure we don't get any of the deprecation warnings so that we can see the warning we are testing for. For touchdown, we have to explicitly silence the covariance matrix is undefined error (which actually already tells us that the problem will be non-identifiable).
JoepVanlier
added a commit
to lumicks/pylake
that referenced
this issue
Jan 30, 2024
pytest changed its warning/exception order starting from 8.0.0 (see pytest-dev/pytest#9036). This updates our tests to fit the new spec. For kymographs, this meant explicitly passing a motion blur parameter such that we don't issue that error instead of what we are looking for. For the dwelltime analysis, we have to make sure we don't get any of the deprecation warnings so that we can see the warning we are testing for. For touchdown, we have to explicitly silence the covariance matrix is undefined error (which actually already tells us that the problem will be non-identifiable).
JoepVanlier
added a commit
to lumicks/pylake
that referenced
this issue
Jan 30, 2024
pytest changed its warning/exception order starting from 8.0.0 (see pytest-dev/pytest#9036). This updates our tests to fit the new spec. For kymographs, this meant explicitly passing a motion blur parameter such that we don't issue that error instead of what we are looking for. For the dwelltime analysis, we have to make sure we don't get any of the deprecation warnings so that we can see the warning we are testing for. For touchdown, we have to explicitly silence the covariance matrix is undefined error (which actually already tells us that the problem will be non-identifiable).
JoepVanlier
added a commit
to lumicks/pylake
that referenced
this issue
Jan 30, 2024
pytest changed its warning/exception order starting from 8.0.0 (see pytest-dev/pytest#9036). This updates our tests to fit the new spec. For kymographs, this meant explicitly passing a motion blur parameter such that we don't issue that error instead of what we are looking for. For the dwelltime analysis, we have to make sure we don't get any of the deprecation warnings so that we can see the warning we are testing for. For touchdown, we have to explicitly silence the covariance matrix is undefined error (which actually already tells us that the problem will be non-identifiable).
JoepVanlier
added a commit
to lumicks/pylake
that referenced
this issue
Jan 30, 2024
pytest changed its warning/exception order starting from 8.0.0 (see pytest-dev/pytest#9036). This updates our tests to fit the new spec. For kymographs, this meant explicitly passing a motion blur parameter such that we don't issue that error instead of what we are looking for. For the dwelltime analysis, we have to make sure we don't get any of the deprecation warnings so that we can see the warning we are testing for. For touchdown, we have to explicitly silence the covariance matrix is undefined error (which actually already tells us that the problem will be non-identifiable).
mgorny
added a commit
to mgorny/pydantic
that referenced
this issue
Jan 30, 2024
Fix `tests/test_validators.py::test_use_no_fields` not to check for a warning that can't be emitted because calling the decorator fails with a `TypeError`. Starting with pytest 8.0.0 (due to pytest-dev/pytest#9036 fix), `pytest.warns()` assertions are enforced even if an exception is raised and consumed by `pytest.raises()`. Bug pydantic#8674
mgorny
added a commit
to mgorny/pydantic
that referenced
this issue
Jan 30, 2024
Emit Pydantic V1 style `@validator` deprecation warnings before raising `PydanticUserError` about incorrect use. This is one of the possible solutions to test failures introduced with pytest 8.0.0, as now `pytest.warns()` assertions are enforced even if an exception raised and caught by `pytest.raises()` (this is pytest-dev/pytest#9036). The alternate possibility would be to remove `pytest.warns()` from respective test functions but I think it's reasonable to emit these warnings, to warn the users that they ought to consider upgrading the code to Pydantic V2 API rather than fixing the immediate issue. Bug pydantic#8674
JoepVanlier
added a commit
to lumicks/pylake
that referenced
this issue
Jan 31, 2024
pytest changed its warning/exception order starting from 8.0.0 (see pytest-dev/pytest#9036). This updates our tests to fit the new spec. For kymographs, this meant explicitly passing a motion blur parameter such that we don't issue that error instead of what we are looking for. For the dwelltime analysis, we have to make sure we don't get any of the deprecation warnings so that we can see the warning we are testing for. For touchdown, we have to explicitly silence the covariance matrix is undefined error (which actually already tells us that the problem will be non-identifiable).
robsdedude
added a commit
to robsdedude/neo4j-python-driver
that referenced
this issue
Feb 15, 2024
In pytest 8 changed the warns assertion was changed to also check for warnings if an error was raised. This used to be different, and the test suite relied (unnecessarily) on this behavior. See also pytest-dev/pytest#9036
jni
pushed a commit
to napari/npe2
that referenced
this issue
Mar 8, 2024
This test is failing in CIs in #340. I think it is because there is no warning raised (not sure why the `UserWarning` is there). It used to pass because of this bug in pytest pytest-dev/pytest#9036, but this was fixed in pytest-dev/pytest#11129 and included in a recent release, thus our CIs are failing. Note that I have update the test to be more specific about the exception raised (`PackageNotFoundError`) but it is not needed, subclass exceptions are still accepted by pytest. Also added a message to be more specific. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
plugin: warnings
related to the warnings builtin plugin
type: bug
problem that needs to be addressed
pip list
from the virtual environment you are usingDescription
It appears that when testing that both a warning is emitted and an exception is raised, the order in which
pytest.raises
andpytest.warns
are used matters and can lead to potentially confusing behavior.Minimal example
For example, the following test passes:
Naively I expected this test to fail as
my_func
is emitting aFutureWarning
, but the test checking that aSyntaxWarning
is emitted.However, if I switch the order of
pytest.raises
andpytest.warns
, then the test fails as expected. That isoutputs
Extra info
pip list:
I'm using
pytest==6.2.4
on a Mac running Big Sur.The text was updated successfully, but these errors were encountered: