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 other tests at every usual test run. I would prefer to select a default-deselected test, when I actually need it. I tried renaming the test from test_longrun
to longrun
and use the command
py.test mytests.py::longrun
but that does not work.
The simplest way to skip a test is to mark it with the skip decorator which may be passed an optional reason . It is also possible to skip imperatively during test execution or setup by calling the pytest. skip(reason) function. This is useful when it is not possible to evaluate the skip condition during import time.
Skipping test functions. The simplest way to skip a test function is to mark it with the skip decorator which may be passed an optional reason : @pytest. mark.
Pytest allows us to use markers on test functions. Markers are used to set various features/attributes to test functions. Pytest provides many inbuilt markers such as xfail, skip and parametrize. Apart from that, users can create their own marker names.
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 config.getoption('longrun')") 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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With