-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
capture warning when exception is raised (fix #9036) #11129
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
Conversation
Seems this change will break the original |
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. |
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 |
Ah not enough coverage... will look at that as well... |
Yep, we'll need to change that behavior. |
Just waiting for #10937 to avoid a merge conflict. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Cheukting!
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>
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: []. ```
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: []. ```
continue PR #10208 by @eltimen
Fixes #9036 and #11032 (same issue)
When a warning is being warned while an exception is raised,
pytest.warns
should still capture the warning if not matched.CC @Zac-HD