(self)
| 529 | |
| 530 | @cpython_only |
| 531 | def test_lost_io_open(self): |
| 532 | # GH-142737: Display the traceback even if io.open is lost |
| 533 | crasher = textwrap.dedent("""\ |
| 534 | import io |
| 535 | import traceback |
| 536 | # Trigger fallback mode |
| 537 | traceback._print_exception_bltin = None |
| 538 | del io.open |
| 539 | raise RuntimeError("should not crash") |
| 540 | """) |
| 541 | |
| 542 | # Create a temporary script to exercise _Py_FindSourceFile |
| 543 | with temp_dir() as script_dir: |
| 544 | script = make_script( |
| 545 | script_dir=script_dir, |
| 546 | script_basename='tb_test_no_io_open', |
| 547 | source=crasher) |
| 548 | rc, stdout, stderr = assert_python_failure(script) |
| 549 | |
| 550 | self.assertEqual(rc, 1) # Make sure it's not a crash |
| 551 | |
| 552 | expected = [b'Traceback (most recent call last):', |
| 553 | f' File "{script}", line 6, in <module>'.encode(), |
| 554 | b'RuntimeError: should not crash'] |
| 555 | self.assertEqual(stderr.splitlines(), expected) |
| 556 | |
| 557 | def test_print_exception(self): |
| 558 | output = StringIO() |
nothing calls this directly
no test coverage detected