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
unittest: on failure, TestCase.run() keeps a reference to the exception #64079
Comments
Test attached unittest_leak.py script: you will see MyException.ninstance counter increased up to 10, whereas I expect that MyException is destroyed at TestCase.run() exit. It looks like a tricky reference cycle between:
Attached unittest_workaround.patch patch works around the issue. |
contextmanager_leak.py: shorter script to demonstrate the issue. Replacing "exc_info = sys.exc_info()" with "sys.exc_info()" works around the issue. |
contextmanager_leak2.py: even simpler example, storing a current frame in a local variable of the frame is enough. generator_workaround.patch is another workaround: call frame.clear() when at generator exit to explicitly break the reference cycle. |
frame_ref_cycle.py: if I understood correctly, unittest_leak.py can be simplified to this script. A frame contains a local variable which contains the frame: reference cycle. |
unittest_leak.patch: Fix the the initial bug, unittest_leak.py. I don't think that it's possible to write a generic fix for frame_ref_cycle.py. Storing sys.exc_info() to format it as a traceback later is a common pattern. Clearing a frame at function exit breaks this use case. |
New changeset 09658ea0b93d by Victor Stinner in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: