When mocking objects, there are some instruments, which allow to change the result of a function.
Let's say, there is some class:
class Worker:
def do_work(self):
return perform_operation()
And I want to test some cases, when do_work()
raises several exceptions in different situations:
@patch(
'my.package.Worker.do_work',
Mock(side_effect=[exc.VeryBadError, exc.NotThatBadError]
))
def test_worker_raise_errors():
worker_user.call_worker()
But there is no way to pass several errors to side_effects
like above, it would run only once and Fail only for exc.VeryBadError
.
When I want to find a way to launch test_worker_raise_errors()
twice for each exception, but w/o creating each test function per exception.
Is there a way to launch one test several times for each exception as a side effect and to see 2 Fails in this case?