From 4c0ba6017d44e6d0beefa6f0ddeff6f97ca25183 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 7 Apr 2019 19:08:59 +0200 Subject: [PATCH] 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. --- testing/conftest.py | 26 ++++++++++++++++++++++++++ testing/test_modimport.py | 2 ++ tox.ini | 1 + 3 files changed, 29 insertions(+) create mode 100644 testing/conftest.py diff --git a/testing/conftest.py b/testing/conftest.py new file mode 100644 index 000000000..fb677cd05 --- /dev/null +++ b/testing/conftest.py @@ -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 diff --git a/testing/test_modimport.py b/testing/test_modimport.py index 33862799b..3d7a07323 100644 --- a/testing/test_modimport.py +++ b/testing/test_modimport.py @@ -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") diff --git a/tox.ini b/tox.ini index 16984dd43..3e6745dc5 100644 --- a/tox.ini +++ b/tox.ini @@ -171,6 +171,7 @@ filterwarnings = pytester_example_dir = testing/example_scripts markers = issue + slow [flake8] max-line-length = 120