|
18 | 18 | from test.support import (Error, captured_output, cpython_only, ALWAYS_EQ, |
19 | 19 | requires_debug_ranges, has_no_debug_ranges, |
20 | 20 | requires_subprocess) |
21 | | -from test.support import script_helper |
22 | | -from test.support import os_helper |
23 | | -from test.support.os_helper import TESTFN, unlink |
| 21 | +from test.support.os_helper import TESTFN, temp_dir, unlink |
24 | 22 | from test.support.script_helper import assert_python_ok, assert_python_failure, make_script |
25 | 23 | from test.support.import_helper import forget |
26 | 24 | from test.support import force_not_colorized, force_not_colorized_test_class |
@@ -528,18 +526,23 @@ def __del__(self): |
528 | 526 |
|
529 | 527 | def test_lost_io_open(self): |
530 | 528 | # GH-142737: Display the traceback even if io.open is lost |
531 | | - code = textwrap.dedent("""\ |
| 529 | + crasher = textwrap.dedent("""\ |
532 | 530 | import io |
533 | 531 | import traceback |
534 | 532 | traceback._print_exception_bltin = None |
535 | 533 | del io.open |
536 | 534 | raise RuntimeError("should not crash") |
537 | 535 | """) |
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) |
| 536 | + |
| 537 | + with temp_dir() as script_dir: |
| 538 | + script = make_script( |
| 539 | + script_dir=script_dir, |
| 540 | + script_basename='tb_test_no_io_open', |
| 541 | + source=crasher) |
541 | 542 | rc, stdout, stderr = assert_python_failure(script) |
| 543 | + |
542 | 544 | self.assertEqual(rc, 1) # Make sure it's not a crash |
| 545 | + |
543 | 546 | expected = [b'Traceback (most recent call last):', |
544 | 547 | f' File "{script}", line 5, in <module>'.encode(), |
545 | 548 | b'RuntimeError: should not crash'] |
|
0 commit comments