[3.6] bpo-23890: Fix ref cycles in TestCase.assertRaises()#858
Merged
Conversation
b866adf to
655f38e
Compare
PamelaM
reviewed
Apr 5, 2017
| with self.assertRaises(TypeError): | ||
| self.assertRaises((ValueError, object)) | ||
|
|
||
| def testAssertRaisesRefcount(self): |
There was a problem hiding this comment.
Given the new try/finally handling and the potential for unexpected behavior, I think the context manager mode needs to be checked as well. I don't see a need for a separate test function, just add something like:
with self.assertRaises(ValueError):
func()
self.assertEqual(refcount, sys.getrefcount(func))
Member
Author
There was a problem hiding this comment.
I don't see any reference cycle when using the context manager protocol.
It seems like bpo-23890 was very specific to the function API: assertRaises(ValueError, func) since you pass func to assertRaises().
with self.assertRaises(ValueError):
func()
Here func variable may also leak in the traceback objects linked to the raisen exception. But again, I'm unable to see any leak here without my fix.
If you still consider that an unit test is needed, please comment http://bugs.python.org/issue23890
unittest.TestCase.assertRaises() now manually breaks a reference cycle to not keep objects alive longer than expected. (cherry picked from commit bbd3cf8)
655f38e to
b41dbb3
Compare
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.
bpo-23890: unittest.TestCase.assertRaises() now manually breaks a
reference cycle to not keep objects alive longer than expected.
(cherry picked from commit bbd3cf8)