From fca89f65c7d2e8780cdc7b6be7c8548eb1f704c1 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 26 Jan 2019 02:42:30 +0300 Subject: [PATCH] unittest: test_unittest: Add test for .assertRaises(AssertionError). Make sure that not raising AssertionError from tested function is properly caught. --- python-stdlib/unittest/test_unittest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python-stdlib/unittest/test_unittest.py b/python-stdlib/unittest/test_unittest.py index 78c3dc9e..645363ce 100644 --- a/python-stdlib/unittest/test_unittest.py +++ b/python-stdlib/unittest/test_unittest.py @@ -111,6 +111,21 @@ class TestUnittestAssertions(unittest.TestCase): def testSkip(self): self.assertFail("this should be skipped") + def testAssert(self): + + e1 = None + try: + + def func_under_test(a): + assert a > 10 + + self.assertRaises(AssertionError, func_under_test, 20) + except AssertionError as e: + e1 = e + + if not e1 or "not raised" not in e1.args[0]: + self.fail("Expected to catch lack of AssertionError from assert in func_under_test") + if __name__ == "__main__": unittest.main()