El Dude
El Dude

Reputation: 5618

Unit tests with with assert raise exception

I just stumbled over this type of code and am bit puzzled by its functionality in unit tests:

with self.assertRaises(MyException):
    foo(some_value)

where foo throws MyException

How does this fit together?

Upvotes: 0

Views: 311

Answers (1)

py_dude
py_dude

Reputation: 832

This is the test of function foo that checks whether it raises MyException or not. The test has positive result if it does, otherwise, it's result is negative.

Upvotes: 1

Related Questions