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