diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2024-10-21 06:53:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-21 06:53:21 (GMT) |
commit | c5c21fee7ae1ea689a351caa454c98e716a6e537 (patch) | |
tree | 19705a0cb736d7f972c816fdb40aeddbea7b9c42 /Lib/test/test_importlib/test_api.py | |
parent | 9256be7ff0ab035cfd262127d893c9bc88b3c84c (diff) | |
download | cpython-c5c21fee7ae1ea689a351caa454c98e716a6e537.zip cpython-c5c21fee7ae1ea689a351caa454c98e716a6e537.tar.gz cpython-c5c21fee7ae1ea689a351caa454c98e716a6e537.tar.bz2 |
gh-125519: Improve traceback if `importlib.reload()` is called with a non-module object (#125520)
Diffstat (limited to 'Lib/test/test_importlib/test_api.py')
-rw-r--r-- | Lib/test/test_importlib/test_api.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py index 973237c..51ea527 100644 --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -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 |