mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
gh-125519: Improve traceback if importlib.reload()
is called with a non-module object (#125520)
This commit is contained in:
parent
9256be7ff0
commit
c5c21fee7a
3 changed files with 18 additions and 1 deletions
|
@ -9,6 +9,7 @@ import sys
|
|||
from test import support
|
||||
from test.support import import_helper
|
||||
from test.support import os_helper
|
||||
import traceback
|
||||
import types
|
||||
import unittest
|
||||
|
||||
|
@ -354,6 +355,20 @@ class ReloadTests:
|
|||
with self.assertRaises(ModuleNotFoundError):
|
||||
self.init.reload(module)
|
||||
|
||||
def test_reload_traceback_with_non_str(self):
|
||||
# gh-125519
|
||||
with support.captured_stdout() as stdout:
|
||||
try:
|
||||
self.init.reload("typing")
|
||||
except TypeError as exc:
|
||||
traceback.print_exception(exc, file=stdout)
|
||||
else:
|
||||
self.fail("Expected TypeError to be raised")
|
||||
printed_traceback = stdout.getvalue()
|
||||
self.assertIn("TypeError", printed_traceback)
|
||||
self.assertNotIn("AttributeError", printed_traceback)
|
||||
self.assertNotIn("module.__spec__.name", printed_traceback)
|
||||
|
||||
|
||||
(Frozen_ReloadTests,
|
||||
Source_ReloadTests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue