[3.12] gh-104090: Fix unittest collectedDurations resources leak (GH-106795) (#106888)

gh-104090: Fix unittest collectedDurations resources leak (GH-106795)
(cherry picked from commit 70b961ed93)

Co-authored-by: Yonatan Bitton <bityob@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-07-19 04:34:54 -07:00 committed by GitHub
parent 0c106a91e8
commit b1c50b80a6
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`.