Skip to content

Commit b1c50b8

Browse files
[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 70b961e) Co-authored-by: Yonatan Bitton <bityob@gmail.com>
1 parent 0c106a9 commit b1c50b8

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Diff for: Lib/unittest/result.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def addDuration(self, test, elapsed):
166166
"""
167167
# support for a TextTestRunner using an old TestResult class
168168
if hasattr(self, "collectedDurations"):
169-
self.collectedDurations.append((test, elapsed))
169+
# Pass test repr and not the test object itself to avoid resources leak
170+
self.collectedDurations.append((str(test), elapsed))
170171

171172
def wasSuccessful(self):
172173
"""Tells whether or not this result was a success."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid creating a reference to the test object in :meth:`~unittest.TestResult.collectedDurations`.

0 commit comments

Comments
 (0)