@@ -808,7 +808,12 @@ def test_closefd_attr(self):
808808 def test_garbage_collection (self ):
809809 # FileIO objects are collected, and collecting them flushes
810810 # all data to disk.
811- with warnings_helper .check_warnings (('' , ResourceWarning )):
811+ #
812+ # Note that using warnings_helper.check_warnings() will keep the
813+ # file alive due to the `source` argument to warn(). So, use
814+ # catch_warnings() instead.
815+ with warnings .catch_warnings ():
816+ warnings .simplefilter ("ignore" , ResourceWarning )
812817 f = self .FileIO (os_helper .TESTFN , "wb" )
813818 f .write (b"abcxxx" )
814819 f .f = f
@@ -1809,7 +1814,11 @@ def test_garbage_collection(self):
18091814 # C BufferedReader objects are collected.
18101815 # The Python version has __del__, so it ends into gc.garbage instead
18111816 self .addCleanup (os_helper .unlink , os_helper .TESTFN )
1812- with warnings_helper .check_warnings (('' , ResourceWarning )):
1817+ # Note that using warnings_helper.check_warnings() will keep the
1818+ # file alive due to the `source` argument to warn(). So, use
1819+ # catch_warnings() instead.
1820+ with warnings .catch_warnings ():
1821+ warnings .simplefilter ("ignore" , ResourceWarning )
18131822 rawio = self .FileIO (os_helper .TESTFN , "w+b" )
18141823 f = self .tp (rawio )
18151824 f .f = f
@@ -2158,7 +2167,11 @@ def test_garbage_collection(self):
21582167 # all data to disk.
21592168 # The Python version has __del__, so it ends into gc.garbage instead
21602169 self .addCleanup (os_helper .unlink , os_helper .TESTFN )
2161- with warnings_helper .check_warnings (('' , ResourceWarning )):
2170+ # Note that using warnings_helper.check_warnings() will keep the
2171+ # file alive due to the `source` argument to warn(). So, use
2172+ # catch_warnings() instead.
2173+ with warnings .catch_warnings ():
2174+ warnings .simplefilter ("ignore" , ResourceWarning )
21622175 rawio = self .FileIO (os_helper .TESTFN , "w+b" )
21632176 f = self .tp (rawio )
21642177 f .write (b"123xxx" )
@@ -4080,7 +4093,8 @@ def test_garbage_collection(self):
40804093 # C TextIOWrapper objects are collected, and collecting them flushes
40814094 # all data to disk.
40824095 # The Python version has __del__, so it ends in gc.garbage instead.
4083- with warnings_helper .check_warnings (('' , ResourceWarning )):
4096+ with warnings .catch_warnings ():
4097+ warnings .simplefilter ("ignore" , ResourceWarning )
40844098 rawio = self .FileIO (os_helper .TESTFN , "wb" )
40854099 b = self .BufferedWriter (rawio )
40864100 t = self .TextIOWrapper (b , encoding = "ascii" )
0 commit comments