[Python-checkins] Fix ResourceWarning in test.test_frame (GH-96831)

miss-islington webhook-mailer at python.org
Fri Sep 16 20:04:04 EDT 2022


https://github.com/python/cpython/commit/d39fce0f038c02bdbb1b379df1cca8297c9c368a
commit: d39fce0f038c02bdbb1b379df1cca8297c9c368a
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-09-16T17:03:57-07:00
summary:

Fix ResourceWarning in test.test_frame (GH-96831)

(cherry picked from commit 303bd880475b510481d86a8c48b62d21d0e3bb53)

Co-authored-by: Dennis Sweeney <36520290+sweeneyde at users.noreply.github.com>

files:
M Lib/test/test_frame.py

diff --git a/Lib/test/test_frame.py b/Lib/test/test_frame.py
index 9fab17684eec..5dda2fbfac37 100644
--- a/Lib/test/test_frame.py
+++ b/Lib/test/test_frame.py
@@ -1,10 +1,12 @@
 import re
 import sys
+import textwrap
 import types
 import unittest
 import weakref
 
 from test import support
+from test.support.script_helper import assert_python_ok
 
 
 class ClearTest(unittest.TestCase):
@@ -238,25 +240,26 @@ def inner():
 class TestIncompleteFrameAreInvisible(unittest.TestCase):
 
     def test_issue95818(self):
-        #See GH-95818 for details
-        import gc
-        self.addCleanup(gc.set_threshold, *gc.get_threshold())
+        # See GH-95818 for details
+        code = textwrap.dedent(f"""
+            import gc
 
-        gc.set_threshold(1,1,1)
-        class GCHello:
-            def __del__(self):
-                print("Destroyed from gc")
+            gc.set_threshold(1,1,1)
+            class GCHello:
+                def __del__(self):
+                    print("Destroyed from gc")
 
-        def gen():
-            yield
-
-        fd = open(__file__)
-        l = [fd, GCHello()]
-        l.append(l)
-        del fd
-        del l
-        gen()
+            def gen():
+                yield
 
+            fd = open({__file__!r})
+            l = [fd, GCHello()]
+            l.append(l)
+            del fd
+            del l
+            gen()
+        """)
+        assert_python_ok("-c", code)
 
 if __name__ == "__main__":
     unittest.main()



More information about the Python-checkins mailing list