summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-09-03 07:30:17 (GMT)
committerGitHub <noreply@github.com>2021-09-03 07:30:17 (GMT)
commitb4b6342848ec0459182a992151099252434cc619 (patch)
tree049ee796fb01dee4844bccc61fb7427eb169ccf4 /Lib
parenta1e15a7a604e6f44cdaf4e106339df62eac5dc9f (diff)
downloadcpython-b4b6342848ec0459182a992151099252434cc619.zip
cpython-b4b6342848ec0459182a992151099252434cc619.tar.gz
cpython-b4b6342848ec0459182a992151099252434cc619.tar.bz2
bpo-45083: Include the exception class qualname when formatting an exception (GH-28119)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_sys.py14
-rw-r--r--Lib/test/test_traceback.py13
2 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index dba4928..12305ca 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -1070,6 +1070,20 @@ class UnraisableHookTest(unittest.TestCase):
self.assertIn("del is broken", report)
self.assertTrue(report.endswith("\n"))
+ def test_original_unraisablehook_exception_qualname(self):
+ 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)
def test_original_unraisablehook_wrong_type(self):
exc = ValueError(42)
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index d1967aa..ee2896c 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -1171,6 +1171,19 @@ class BaseExceptionReportingTests:
exp = "\n".join(expected)
self.assertEqual(exp, err)
+ def test_format_exception_only_qualname(self):
+ class A:
+ class B:
+ class X(Exception):
+ def __str__(self):
+ return "I am X"
+ pass
+ err = self.get_report(A.B.X())
+ str_value = 'I am X'
+ str_name = '.'.join([A.B.X.__module__, A.B.X.__qualname__])
+ exp = "%s: %s\n" % (str_name, str_value)
+ self.assertEqual(exp, err)
+
class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
#