From a9faa4d4ab457c08e2f49d83c532d20fe98e1f86 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 16 Mar 2020 16:12:51 +0100 Subject: [PATCH] core/tests: fix inline variant of assertRaises otherwise code like the following would fail: >>> self.assertRaises(AssertionError, ensure, False) because the AssertionError raised internally by `ensure` would be conflated with the AssertionError raised by the tested function --- core/tests/unittest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/tests/unittest.py b/core/tests/unittest.py index 4cb339fe38..a78a68d03c 100644 --- a/core/tests/unittest.py +++ b/core/tests/unittest.py @@ -119,11 +119,12 @@ class TestCase: return AssertRaisesContext(exc) try: func(*args, **kwargs) - ensure(False, "%r not raised" % exc) except Exception as e: if isinstance(e, exc): return raise + else: + ensure(False, "%r not raised" % exc) def assertListEqual(self, x, y, msg=''): if len(x) != len(y):