Add a conftest to prefer faster tests

This uses pytest_collection_modifyitems for pytest's own tests to order
them, preferring faster ones via quick'n'dirty heuristics only for now.
This commit is contained in:
Daniel Hahler 2019-04-07 19:08:59 +02:00
parent b549438423
commit 4c0ba6017d
3 changed files with 29 additions and 0 deletions

26
testing/conftest.py Normal file
View File

@ -0,0 +1,26 @@
def pytest_collection_modifyitems(config, items):
"""Prefer faster tests."""
fast_items = []
slow_items = []
neutral_items = []
slow_fixturenames = ("testdir",)
for item in items:
try:
fixtures = item.fixturenames
except AttributeError:
# doctest at least
# (https://github.com/pytest-dev/pytest/issues/5070)
neutral_items.append(item)
else:
if any(x for x in fixtures if x in slow_fixturenames):
slow_items.append(item)
else:
marker = item.get_closest_marker("slow")
if marker:
slow_items.append(item)
else:
fast_items.append(item)
items[:] = fast_items + neutral_items + slow_items

View File

@ -6,6 +6,8 @@ import py
import _pytest
import pytest
pytestmark = pytest.mark.slow
MODSET = [
x
for x in py.path.local(_pytest.__file__).dirpath().visit("*.py")

View File

@ -171,6 +171,7 @@ filterwarnings =
pytester_example_dir = testing/example_scripts
markers =
issue
slow
[flake8]
max-line-length = 120