]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-104090: Fix unittest collectedDurations resources leak (GH-106795) (#106888)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 19 Jul 2023 11:34:54 +0000 (04:34 -0700)
committerGitHub <noreply@github.com>
Wed, 19 Jul 2023 11:34:54 +0000 (11:34 +0000)
gh-104090: Fix unittest collectedDurations resources leak (GH-106795)
(cherry picked from commit 70b961ed93f67e34d0624e178f6029c886afaeee)

Co-authored-by: Yonatan Bitton <bityob@gmail.com>
Lib/unittest/result.py
Misc/NEWS.d/next/Tests/2023-07-16-02-57-08.gh-issue-104090.cKtK7g.rst [new file with mode: 0644]

index 7757dba9670b43a16e7e94e8208b7a1f1dcec6d3..3ace0a5b7bf2efb209630c5a7f9f6b7aafc1ef7d 100644 (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."""
diff --git a/Misc/NEWS.d/next/Tests/2023-07-16-02-57-08.gh-issue-104090.cKtK7g.rst b/Misc/NEWS.d/next/Tests/2023-07-16-02-57-08.gh-issue-104090.cKtK7g.rst
new file mode 100644 (file)
index 0000000..5cc6c5b
--- /dev/null
@@ -0,0 +1 @@
+Avoid creating a reference to the test object in :meth:`~unittest.TestResult.collectedDurations`.