How to add sqlalchemy.exc.IntegrityError as side effect to mock objects?
<p>I am testing a function that needs a mock object. This object might raise IntegrityError so I am adding this error as side effect to the mock object </p>

<pre><code>def test_(self, mock_object):
        mock_object.side_effect = IntegrityError
</code></pre>

<p>This is somehow not correct as it raises an exception saying <code>__init__() takes at least 4 arguments (1 given)</code>
What is the correct way of doing this?</p>

<p>Just build a one-line function raising an integrity error, and adds that as the side-effect:</p>

<pre><code>x = Mock()

def b():
    raise IntegrityError('Mock', 'mock', 'mock')

x.side_effect = b
x()
</code></pre>

python unit-testing python-mock