summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sys.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-09-05 15:54:13 (GMT)
committerGitHub <noreply@github.com>2021-09-05 15:54:13 (GMT)
commit9e31b3952f6101ef71ec029481b972169ab0e0f1 (patch)
treeb325ae97e170eafbdb9b58a5cc1755446c5667b5 /Lib/test/test_sys.py
parentb01fd533fef78b088674bad73267b89bea98e904 (diff)
downloadcpython-9e31b3952f6101ef71ec029481b972169ab0e0f1.zip
cpython-9e31b3952f6101ef71ec029481b972169ab0e0f1.tar.gz
cpython-9e31b3952f6101ef71ec029481b972169ab0e0f1.tar.bz2
bpo-41031: Match C and Python code formatting of unprintable exceptions and exceptions in the __main__ module. (GH-28139)
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r--Lib/test/test_sys.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 12305ca..e98803b 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -1071,19 +1071,29 @@ class UnraisableHookTest(unittest.TestCase):
self.assertTrue(report.endswith("\n"))
def test_original_unraisablehook_exception_qualname(self):
+ # See bpo-41031, bpo-45083.
+ # Check that the exception is printed with its qualified name
+ # rather than just classname, and the module names appears
+ # unless it is one of the hard-coded exclusions.
class A:
class B:
class X(Exception):
pass
- with test.support.captured_stderr() as stderr, \
- test.support.swap_attr(sys, 'unraisablehook',
- sys.__unraisablehook__):
- expected = self.write_unraisable_exc(
- A.B.X(), "msg", "obj");
- report = stderr.getvalue()
- testName = 'test_original_unraisablehook_exception_qualname'
- self.assertIn(f"{testName}.<locals>.A.B.X", report)
+ for moduleName in 'builtins', '__main__', 'some_module':
+ with self.subTest(moduleName=moduleName):
+ A.B.X.__module__ = moduleName
+ with test.support.captured_stderr() as stderr, \
+ test.support.swap_attr(sys, 'unraisablehook',
+ sys.__unraisablehook__):
+ expected = self.write_unraisable_exc(
+ A.B.X(), "msg", "obj");
+ report = stderr.getvalue()
+ self.assertIn(A.B.X.__qualname__, report)
+ if moduleName in ['builtins', '__main__']:
+ self.assertNotIn(moduleName + '.', report)
+ else:
+ self.assertIn(moduleName + '.', report)
def test_original_unraisablehook_wrong_type(self):
exc = ValueError(42)