Test with mock pass when run individually but not when together

I want test if a function is called in a view.

My view is something like that:

def my_view(request):
    data = request.data
    return Response("ok")

And my test:

def mock_my_function(mocker):
    return mocker.patch("path.for.my.function")

def test_my_test(
    mock_my_function, db, client
    data = {"some": "thing"}
    resp = client.post(
    assert resp.data == "ok"

Running this test individually, it's ok. Works! But, when I run all tests, this test fails. Pytest show me this error:

E       AssertionError: Expected 'mock_my_function' to have been called.
Back to Top