codedump.ch

Python Mocking 101

2024-06-24

Python Mocking 101: Fake it before you make it

@patch("module.mock_function")
def test_thing(..., mock_call):
    mock_call.return_value = {"foo": "bar"}

    module.mock_function(a, b, c)

    mock_call.assert_called_once_with(a, b, c)