title: How do I define a patch globally with autouse?
body: <p>Right now I do this in a few tests to mock a 3rd party API:</p>
  <pre><code>@patch(&quot;some.api.execute&quot;)
  def sometest(
      mock_the_api, blah, otherstuff
  ):
      mock_the_api.return_value = &quot;mocked response&quot;
      my_func_that_uses_api(blah, otherstuff)
  </code></pre>
  <p>This works and prevents my_func_that_uses_api() (which calls the API) from making actual outbound calls. But I do this 4-5 times and will probably add more in the future. I'd like to mock this globally for all my tests.</p>
  <p>I see in <a href="https://docs.pytest.org/en/latest/monkeypatch.html" rel="nofollow noreferrer">the docs</a> this example:</p>
  <pre><code>@pytest.fixture(autouse=True)
  def no_requests(monkeypatch):
      &quot;&quot;&quot;Remove requests.sessions.Session.request for all tests.&quot;&quot;&quot;
      monkeypatch.delattr(&quot;requests.sessions.Session.request&quot;)
  </code></pre>
  <p>How do I do that but with patching the API response?</p>
  <p>I tried <code>monkeypatch.patch(&quot;some.api.execute&quot;)</code> but get error <code>AttributeError: 'MonkeyPatch' object has no attribute 'patch'</code></p>
  <p>Also, to add, I'm not using any classes in my pytest tests (like test cases) - I'd like to avoid uses classes in my pytests tests for now.</p>