# In pyprojct.toml
[tool.pytest.ini-options]
markers = ["slow: mark tests as slow (deselect with '--runslow')"]
Add the following to your conftest.py
file:
def pytest_addoption(parser):
parser.addoption(
"--runslow", action="store_true", default=False, help="run slow tests"
)
def pytest_collection_modifyitems(config, items):
if config.getoption("--runslow"):
return
skip_slow = pytest.mark.skip(reason="need --runslow option to sun")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
In your test file:
import pytest
@pytest.mark.slow
def test_something_slow():
pass
Run pytest without the --runslow
flag. Any marked test will be skipped.
To run slow tests, run pytest --runslow .