gh-104090: Fix unittest collectedDurations resources leak (#106795)

This commit is contained in:
Yonatan Bitton 2023-07-19 14:03:47 +03:00 committed by GitHub
parent e6f96cf9c6
commit 70b961ed93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -166,7 +166,8 @@ class TestResult(object):
"""
# support for a TextTestRunner using an old TestResult class
if hasattr(self, "collectedDurations"):
self.collectedDurations.append((test, elapsed))
# Pass test repr and not the test object itself to avoid resources leak
self.collectedDurations.append((str(test), elapsed))
def wasSuccessful(self):
"""Tells whether or not this result was a success."""

View File

@ -0,0 +1 @@
Avoid creating a reference to the test object in :meth:`~unittest.TestResult.collectedDurations`.