From 9bc0b15f11cb5089ac4b8666fc9a8d181b11f853 Mon Sep 17 00:00:00 2001 From: Oliver Joos Date: Thu, 10 Feb 2022 00:45:53 +0100 Subject: [PATCH] unittest: Make AssertRaisesContext store exception for later retrieval. The statement "with assertRaises(errtype) as ctxt" checks the type of a raised exception, but did not store the exception into ctxt like unittest of CPython. The exception instance is usually used to check its message or other args. --- python-stdlib/unittest/unittest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python-stdlib/unittest/unittest.py b/python-stdlib/unittest/unittest.py index 35ed14ac..8ecab0a2 100644 --- a/python-stdlib/unittest/unittest.py +++ b/python-stdlib/unittest/unittest.py @@ -24,6 +24,8 @@ class AssertRaisesContext: if exc_type is None: assert False, "%r not raised" % self.expected if issubclass(exc_type, self.expected): + # store exception for later retrieval + self.exception = exc_value return True return False