Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 70b961e

Browse filesBrowse files
authored
gh-104090: Fix unittest collectedDurations resources leak (#106795)
1 parent e6f96cf commit 70b961e
Copy full SHA for 70b961e

File tree

Expand file treeCollapse file tree

2 files changed

+3
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+3
-1
lines changed

‎Lib/unittest/result.py

Copy file name to clipboardExpand all lines: Lib/unittest/result.py
+2-1Lines changed: 2 additions & 1 deletion
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."""
+1Lines changed: 1 addition & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.