capture warning when exception is raised (fix #9036)#11129
Merged
Zac-HD merged 1 commit intopytest-dev:mainfrom Jul 1, 2023
Merged
capture warning when exception is raised (fix #9036)#11129Zac-HD merged 1 commit intopytest-dev:mainfrom
Zac-HD merged 1 commit intopytest-dev:mainfrom
Conversation
Contributor
Author
|
Seems this change will break the original |
Contributor
Author
|
This is the behaviour that changes: If the block of the code being tested by deprecated_call() raises an exception, it must raise the exception undisturbed. |
Contributor
Author
|
From the previous discussion, it seems if we fix this missing @Zac-HD I would need advice on this, if I got a green light to change this behaviour then I can remove the old test |
Contributor
Author
|
Ah not enough coverage... will look at that as well... |
Member
|
Yep, we'll need to change that behavior. |
Member
|
Just waiting for #10937 to avoid a merge conflict. |
11 tasks
jni
pushed a commit
to napari/npe2
that referenced
this pull request
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>
imphil
added a commit
to imphil/cocotb
that referenced
this pull request
Apr 17, 2024
Pytest 8 introduced new behavior for `pytest.warn()`, which isn't compatible with our code in `test_unicode_handle_assignment_deprecated`. Update the test to be skipped entirely for Icarus and GHDL instead of testing for specific exceptions. (The test doesn't do anything on these simulators anyways.) See also pytest-dev/pytest#11129 Error message, as seen in CI: ``` 1.00ns INFO cocotb.regression running test_unicode_handle_assignment_deprecated (2/195) 1.00ns INFO cocotb.regression test_unicode_handle_assignment_deprecated failed: errored with unexpected type Traceback (most recent call last): File "/home/runner/work/cocotb/cocotb/tests/test_cases/test_cocotb/test_deprecated.py", line 39, in test_unicode_handle_assignment_deprecated dut.stream_in_string.value = "Bad idea" File "/home/runner/work/cocotb/cocotb/.nox/dev_test_sim-sim-icarus-toplevel_lang-verilog-gpi_interface-vpi/lib/python3.8/site-packages/cocotb/handle.py", line 370, in __getattr__ raise AttributeError(f"{self._name} contains no object named {name}") AttributeError: sample_module contains no object named stream_in_string During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/runner/work/cocotb/cocotb/tests/test_cases/test_cocotb/test_deprecated.py", line 39, in test_unicode_handle_assignment_deprecated dut.stream_in_string.value = "Bad idea" File "/home/runner/work/cocotb/cocotb/.nox/dev_test_sim-sim-icarus-toplevel_lang-verilog-gpi_interface-vpi/lib/python3.8/site-packages/_pytest/recwarn.py", line 322, in __exit__ fail( File "/home/runner/work/cocotb/cocotb/.nox/dev_test_sim-sim-icarus-toplevel_lang-verilog-gpi_interface-vpi/lib/python3.8/site-packages/_pytest/outcomes.py", line 166, in fail raise Failed(msg=reason, pytrace=pytrace) Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>,) were emitted. Emitted warnings: []. ```
imphil
added a commit
to cocotb/cocotb
that referenced
this pull request
Apr 18, 2024
Pytest 8 introduced new behavior for `pytest.warn()`, which isn't compatible with our code in `test_unicode_handle_assignment_deprecated`. Update the test to be skipped entirely for Icarus and GHDL instead of testing for specific exceptions. (The test doesn't do anything on these simulators anyways.) See also pytest-dev/pytest#11129 Error message, as seen in CI: ``` 1.00ns INFO cocotb.regression running test_unicode_handle_assignment_deprecated (2/195) 1.00ns INFO cocotb.regression test_unicode_handle_assignment_deprecated failed: errored with unexpected type Traceback (most recent call last): File "/home/runner/work/cocotb/cocotb/tests/test_cases/test_cocotb/test_deprecated.py", line 39, in test_unicode_handle_assignment_deprecated dut.stream_in_string.value = "Bad idea" File "/home/runner/work/cocotb/cocotb/.nox/dev_test_sim-sim-icarus-toplevel_lang-verilog-gpi_interface-vpi/lib/python3.8/site-packages/cocotb/handle.py", line 370, in __getattr__ raise AttributeError(f"{self._name} contains no object named {name}") AttributeError: sample_module contains no object named stream_in_string During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/runner/work/cocotb/cocotb/tests/test_cases/test_cocotb/test_deprecated.py", line 39, in test_unicode_handle_assignment_deprecated dut.stream_in_string.value = "Bad idea" File "/home/runner/work/cocotb/cocotb/.nox/dev_test_sim-sim-icarus-toplevel_lang-verilog-gpi_interface-vpi/lib/python3.8/site-packages/_pytest/recwarn.py", line 322, in __exit__ fail( File "/home/runner/work/cocotb/cocotb/.nox/dev_test_sim-sim-icarus-toplevel_lang-verilog-gpi_interface-vpi/lib/python3.8/site-packages/_pytest/outcomes.py", line 166, in fail raise Failed(msg=reason, pytrace=pytrace) Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>,) were emitted. Emitted warnings: []. ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
continue PR #10208 by @eltimen
Fixes #9036 and #11032 (same issue)
When a warning is being warned while an exception is raised,
pytest.warnsshould still capture the warning if not matched.CC @Zac-HD