Skip to content

Commit

Permalink
[3.12] pythongh-104090: Fix unittest collectedDurations resources leak (
Browse files Browse the repository at this point in the history
pythonGH-106795) (python#106888)

pythongh-104090: Fix unittest collectedDurations resources leak (pythonGH-106795)
(cherry picked from commit 70b961e)

Co-authored-by: Yonatan Bitton <[email protected]>
  • Loading branch information
miss-islington and bityob authored Jul 19, 2023
1 parent 0c106a9 commit b1c50b8
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 b1c50b8

Please sign in to comment.