Skip to content

Commit f0aec1f

Browse files
add a test on wrong name in ModuleNotFoundError
1 parent 9aa6631 commit f0aec1f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Lib/test/test_traceback.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5456,5 +5456,17 @@ def test_suggestion_still_works_for_non_lazy_attributes(self):
54565456
self.assertNotIn(b"BAR_MODULE_LOADED", stdout)
54575457

54585458

5459+
class TestNoCrashInTracebackException(unittest.TestCase):
5460+
def test_module_not_found_error_with_bad_name(self):
5461+
exc = ModuleNotFoundError(name=NotImplemented)
5462+
try:
5463+
te = traceback.TracebackException.from_exception(exc)
5464+
except Exception as e:
5465+
self.fail(f"TracebackException raised unexpected exception: {e!r}")
5466+
else:
5467+
msg = "".join(te.format())
5468+
self.assertEqual(msg, "ModuleNotFoundError\n")
5469+
5470+
54595471
if __name__ == "__main__":
54605472
unittest.main()

0 commit comments

Comments
 (0)