Disable autouse fixtures on specific pytest marks
In case you have your endtoend
tests in specific modules or classes you could also just override the no_requests
fixture locally, for example assuming you group all your integration tests in a file called end_to_end.py
:
# test_end_to_end.py
@pytest.fixture(autouse=True)
def no_requests():
return
def test_api_returns_ok():
# Should make a real request.
assert make_request().status_code == 200
You can also use the request
object in your fixture to check the markers used on the test, and don't do anything if a specific marker is set:
import pytest
@pytest.fixture(autouse=True)
def autofixt(request):
if 'noautofixt' in request.keywords:
return
print("patching stuff")
def test1():
pass
@pytest.mark.noautofixt
def test2():
pass
Output with -vs
:
x.py::test1 patching stuff
PASSED
x.py::test2 PASSED