Skip to content

Commit

Permalink
pythongh-104090: Fix unittest collectedDurations resources leak (pyth…
Browse files Browse the repository at this point in the history
  • Loading branch information
bityob authored Jul 19, 2023
1 parent e6f96cf commit 70b961e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Lib/unittest/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def addDuration(self, test, elapsed):
"""
# 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."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid creating a reference to the test object in :meth:`~unittest.TestResult.collectedDurations`.

0 comments on commit 70b961e

Please sign in to comment.