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:
parent
b549438423
commit
4c0ba6017d
|
@ -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
|
|
@ -6,6 +6,8 @@ import py
|
||||||
import _pytest
|
import _pytest
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.slow
|
||||||
|
|
||||||
MODSET = [
|
MODSET = [
|
||||||
x
|
x
|
||||||
for x in py.path.local(_pytest.__file__).dirpath().visit("*.py")
|
for x in py.path.local(_pytest.__file__).dirpath().visit("*.py")
|
||||||
|
|
Loading…
Reference in New Issue