Replies: 1 comment
-
First, this isn't specific to try:
Case2()
except TypeError as e:
exc = e I think what happens (didn't verify), is that But more generally, the Python language itself does not guarantee " My recommendation would be:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to ensure that every test in a codebase checks that there were no unexpected unraisable exceptions. My current approach is to turn the PyTest warning that is propagated into an exception - any unraisables will result in a failing case:
This results in:
Not surprisingly, this approach fails if there is a reference to the object somewhere. Unfortunately, it looks like PyTest holds on to such a reference within an exception:
This can be worked around by explicitly
del err
at the end of the test (as discussed in #8153 (comment)).My questions are:
del
the error object (and avoid any other gotchas like that) in order to be sure that__del__
implementations aren't accidentally raising__del__
? We could use mock, or a pattern such as the following, but are there better approaches?The problem with the latter approach is that it will result in
__del__
being called twice, so some further patching is needed to get it to behave nicely in error modes.Beta Was this translation helpful? Give feedback.
All reactions