Skip to content

Commit fca89f6

Browse files
pfalconpi-anl
authored andcommitted
unittest: test_unittest: Add test for .assertRaises(AssertionError).
Make sure that not raising AssertionError from tested function is properly caught.
1 parent 669d343 commit fca89f6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

python-stdlib/unittest/test_unittest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ def testRaises(self):
111111
def testSkip(self):
112112
self.assertFail("this should be skipped")
113113

114+
def testAssert(self):
115+
116+
e1 = None
117+
try:
118+
119+
def func_under_test(a):
120+
assert a > 10
121+
122+
self.assertRaises(AssertionError, func_under_test, 20)
123+
except AssertionError as e:
124+
e1 = e
125+
126+
if not e1 or "not raised" not in e1.args[0]:
127+
self.fail("Expected to catch lack of AssertionError from assert in func_under_test")
128+
114129

115130
if __name__ == "__main__":
116131
unittest.main()

0 commit comments

Comments
 (0)