MCPcopy Index your code
hub / github.com/python/cpython / test_lost_io_open

Method test_lost_io_open

Lib/test/test_traceback.py:531–555  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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()

Callers

nothing calls this directly

Calls 7

temp_dirFunction · 0.90
make_scriptFunction · 0.90
assert_python_failureFunction · 0.90
dedentMethod · 0.45
assertEqualMethod · 0.45
encodeMethod · 0.45
splitlinesMethod · 0.45

Tested by

no test coverage detected