Skip to content

Commit d39fce0

Browse files
Fix ResourceWarning in test.test_frame (GH-96831)
(cherry picked from commit 303bd88) Co-authored-by: Dennis Sweeney <[email protected]>
1 parent 92a0e81 commit d39fce0

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

Lib/test/test_frame.py

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import re
22
import sys
3+
import textwrap
34
import types
45
import unittest
56
import weakref
67

78
from test import support
9+
from test.support.script_helper import assert_python_ok
810

911

1012
class ClearTest(unittest.TestCase):
@@ -238,25 +240,26 @@ def inner():
238240
class TestIncompleteFrameAreInvisible(unittest.TestCase):
239241

240242
def test_issue95818(self):
241-
#See GH-95818 for details
242-
import gc
243-
self.addCleanup(gc.set_threshold, *gc.get_threshold())
243+
# See GH-95818 for details
244+
code = textwrap.dedent(f"""
245+
import gc
244246
245-
gc.set_threshold(1,1,1)
246-
class GCHello:
247-
def __del__(self):
248-
print("Destroyed from gc")
247+
gc.set_threshold(1,1,1)
248+
class GCHello:
249+
def __del__(self):
250+
print("Destroyed from gc")
249251
250-
def gen():
251-
yield
252-
253-
fd = open(__file__)
254-
l = [fd, GCHello()]
255-
l.append(l)
256-
del fd
257-
del l
258-
gen()
252+
def gen():
253+
yield
259254
255+
fd = open({__file__!r})
256+
l = [fd, GCHello()]
257+
l.append(l)
258+
del fd
259+
del l
260+
gen()
261+
""")
262+
assert_python_ok("-c", code)
260263

261264
if __name__ == "__main__":
262265
unittest.main()

0 commit comments

Comments
 (0)