Skip to content

Commit 9bc0b15

Browse files
oliver-joosdpgeorge
authored andcommitted
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.
1 parent 459e139 commit 9bc0b15

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

python-stdlib/unittest/unittest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def __exit__(self, exc_type, exc_value, tb):
2424
if exc_type is None:
2525
assert False, "%r not raised" % self.expected
2626
if issubclass(exc_type, self.expected):
27+
# store exception for later retrieval
28+
self.exception = exc_value
2729
return True
2830
return False
2931

0 commit comments

Comments
 (0)