py.test recipes for slowness

Useful material on how to deal with slow tests in py.test, a bit buried in the docs:

From, to get a list of the slowest 10 test durations:

pytest --durations=10

From, to skip slow tests unless they are requested:

# content of

import pytest
def pytest_addoption(parser):
    parser.addoption("--runslow", action="store_true",
        help="run slow tests")

# content of
import pytest

slow = pytest.mark.skipif(
    not pytest.config.getoption("--runslow"),
    reason="need --runslow option to run"

def test_func_fast():

def test_func_slow():

Very convenient to know.

Comments Off on py.test recipes for slowness

Filed under software engineering

Comments are closed.