A little background
You can limit the amount of tests in many ways. For example, you can execute a single test by passing its full name as parameter:
$ pytest tests/test_spam.py::TestEggs::test_bacon
will run only the test method test_bacon
in class TestEggs
in module tests/test_spam.py
.
If you don't know the exact test name, you can find it out by executing
$ pytest --collect-only -q
You can combine both commands to execute a limited amount of tests:
$ pytest -q --collect-only 2>&1 | head -n N | xargs pytest -sv
will execute first N
collected tests.
You can also implement the --limit
argument yourself if you want to. Example:
def pytest_addoption(parser):
parser.addoption('--limit', action='store', default=-1, type=int, help='tests limit')
def pytest_collection_modifyitems(session, config, items):
limit = config.getoption('--limit')
if limit >= 0:
items[:] = items[:limit]
Now the above command becomes equal to
$ pytest --limit N