I have a long run test, which lasts 2 days, which I don\'t want to include in a usual test run. I also don\'t want to type command line parameters, that would deselect it and ot
try to decorate your test as @pytest.mark.longrun
in your conftest.py
def pytest_addoption(parser):
parser.addoption('--longrun', action='store_true', dest="longrun",
default=False, help="enable longrundecorated tests")
def pytest_configure(config):
if not config.option.longrun:
setattr(config.option, 'markexpr', 'not longrun')
Alternatively to the pytest_configure
solution above I had found pytest.mark.skipif
.
You need to put pytest_addoption()
into conftest.py
def pytest_addoption(parser):
parser.addoption('--longrun', action='store_true', dest="longrun",
default=False, help="enable longrundecorated tests")
And you use skipif
in the test file.
import pytest
longrun = pytest.mark.skipif(
not pytest.config.option.longrun,
reason="needs --longrun option to run")
def test_usual(request):
assert false, 'usual test failed'
@longrun
def test_longrun(request):
assert false, 'longrun failed'
In the command line
py.test
will not execute test_longrun()
, but
py.test --longrun
will also execute test_longrun()
.