I am trying to mock a simple function but I get an AttributeError and have no clue on how to fix it. def my_function(): return "original" def mock_my_function(): return "mocked" def test_my_function(monkeypatch): monkeypatch.setattr(__name__, 'my_function', mock_my_function) assert my_function() == "mocked" What should I put in __name__'s place to make it work? Continue reading...