1818from test .support import (Error , captured_output , cpython_only , ALWAYS_EQ ,
1919 requires_debug_ranges , has_no_debug_ranges ,
2020 requires_subprocess )
21+ from test .support import script_helper
22+ from test .support import os_helper
2123from test .support .os_helper import TESTFN , unlink
2224from test .support .script_helper import assert_python_ok , assert_python_failure , make_script
2325from test .support .import_helper import forget
@@ -524,7 +526,7 @@ def __del__(self):
524526 b'ZeroDivisionError: division by zero' ]
525527 self .assertEqual (stderr .splitlines (), expected )
526528
527- def test_when_io_is_lost (self ):
529+ def test_lost_io_open (self ):
528530 # GH-142737: Display the traceback even if io.open is lost
529531 code = textwrap .dedent ("""\
530532 import io
@@ -533,10 +535,13 @@ def test_when_io_is_lost(self):
533535 del io.open
534536 raise RuntimeError("should not crash")
535537 """ )
536- rc , stdout , stderr = assert_python_failure ('-c' , code )
537- self .assertEqual (rc , 1 )
538+ with os_helper .temp_dir () as temp_dir :
539+ script = script_helper .make_script (
540+ script_dir = temp_dir , script_basename = 'tb_test_no_io_open' , source = code )
541+ rc , stdout , stderr = assert_python_failure (script )
542+ self .assertEqual (rc , 1 ) # Make sure it's not a crash
538543 expected = [b'Traceback (most recent call last):' ,
539- b ' File "<string> ", line 5, in <module>' ,
544+ f ' File "{ script } ", line 5, in <module>'. encode () ,
540545 b'RuntimeError: should not crash' ]
541546 self .assertEqual (stderr .splitlines (), expected )
542547
0 commit comments