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.
pull/551/head
Oliver Joos 2022-02-10 00:45:53 +01:00 zatwierdzone przez Damien George
rodzic 459e13921a
commit 9bc0b15f11
1 zmienionych plików z 2 dodań i 0 usunięć

Wyświetl plik

@ -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