From 9d327d9db2dc9606fd510f257c4f3133b6b0fb9c Mon Sep 17 00:00:00 2001 From: sweeneyde Date: Wed, 14 Sep 2022 15:31:22 -0400 Subject: [PATCH] Fix ResourceWarning in test.test_frame --- Lib/test/test_frame.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_frame.py b/Lib/test/test_frame.py index 9fab17684eec02..5dda2fbfac374c 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()