From 669d343feb80f17eb932f5f576e6ebfb79cd3295 Mon Sep 17 00:00:00 2001 From: sss Date: Wed, 31 Oct 2018 15:59:56 +1100 Subject: [PATCH] unittest: Allow to catch AssertionError with assertRaises(). Without this change, current implementaiton produces a false positive result for AssertionError type. Example of falsely passing test code: def test(a, b): assert a > 10 assert b > 10 self.assertRaises(AssertionError, test, 20, 20) --- python-stdlib/unittest/unittest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python-stdlib/unittest/unittest.py b/python-stdlib/unittest/unittest.py index 55468b54..f6772ddb 100644 --- a/python-stdlib/unittest/unittest.py +++ b/python-stdlib/unittest/unittest.py @@ -126,12 +126,13 @@ class TestCase: try: func(*args, **kwargs) - assert False, "%r not raised" % exc except Exception as e: if isinstance(e, exc): return raise + assert False, "%r not raised" % exc + def skip(msg): def _decor(fun):