Skip to content

Commit f96bb14

Browse files
committed
Adds assertResultNotRaises method to TestCase
1 parent 4262625 commit f96bb14

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/unittest_extensions/case.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ def assertResultRaises(self, expected_exception):
216216
with self.assertRaises(expected_exception):
217217
self.result()
218218

219+
def assertResultNotRaises(self):
220+
"""
221+
Fail if an exception is raised by the result. This is equivalent to
222+
just executing the result `self.result()`.
223+
"""
224+
self.result()
225+
219226
def assertResultRaisesRegex(self, expected_exception, expected_regex):
220227
"""
221228
Fail unless an exception of class expected_exception is raised by the

src/unittest_extensions/tests/test_use_case.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,16 @@ def test_args_raises_test_error(self):
403403
self.assertResultRaisesRegex(
404404
TestError, "No 'subject' method found; perhaps you mispelled it?"
405405
)
406+
407+
408+
class TestAssertResultNotRaises(TestCase):
409+
def subject(self, r=False):
410+
if r:
411+
raise KeyError
412+
413+
def test_does_not_raise(self):
414+
self.assertResultNotRaises()
415+
416+
@args(r=True)
417+
def test_raises(self):
418+
self.assertResultRaises(KeyError)

0 commit comments

Comments
 (0)