Skip to content

Commit 669d343

Browse files
ssspi-anl
authored andcommitted
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)
1 parent 663a3d6 commit 669d343

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

python-stdlib/unittest/unittest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ def assertRaises(self, exc, func=None, *args, **kwargs):
126126

127127
try:
128128
func(*args, **kwargs)
129-
assert False, "%r not raised" % exc
130129
except Exception as e:
131130
if isinstance(e, exc):
132131
return
133132
raise
134133

134+
assert False, "%r not raised" % exc
135+
135136

136137
def skip(msg):
137138
def _decor(fun):

0 commit comments

Comments
 (0)