How can I use pytest.raises with multiple exceptions? How can I use pytest.raises with multiple exceptions? python-3.x python-3.x

How can I use pytest.raises with multiple exceptions?


Pass the exceptions as a tuple to raises:

with pytest.raises( (MachineError, NotImplementedError) ):    verb = ...

In the source for pytest, pytest.raises may:

In Python 3, except statements can take a tuple of exceptions. The issubclass function can also take a tuple. Therefore, using a tuple should be acceptable in either situation.