Skip to content

Commit fcbfdef

Browse files
authored
Merge pull request #5071 from blueyed/prefer-fast
Add a conftest to prefer faster tests
2 parents 3fa329c + 4c0ba60 commit fcbfdef

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

testing/conftest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def pytest_collection_modifyitems(config, items):
2+
"""Prefer faster tests."""
3+
fast_items = []
4+
slow_items = []
5+
neutral_items = []
6+
7+
slow_fixturenames = ("testdir",)
8+
9+
for item in items:
10+
try:
11+
fixtures = item.fixturenames
12+
except AttributeError:
13+
# doctest at least
14+
# (https://github.com/pytest-dev/pytest/issues/5070)
15+
neutral_items.append(item)
16+
else:
17+
if any(x for x in fixtures if x in slow_fixturenames):
18+
slow_items.append(item)
19+
else:
20+
marker = item.get_closest_marker("slow")
21+
if marker:
22+
slow_items.append(item)
23+
else:
24+
fast_items.append(item)
25+
26+
items[:] = fast_items + neutral_items + slow_items

testing/test_modimport.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import _pytest
77
import pytest
88

9+
pytestmark = pytest.mark.slow
10+
911
MODSET = [
1012
x
1113
for x in py.path.local(_pytest.__file__).dirpath().visit("*.py")

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ filterwarnings =
171171
pytester_example_dir = testing/example_scripts
172172
markers =
173173
issue
174+
slow
174175

175176
[flake8]
176177
max-line-length = 120

0 commit comments

Comments
 (0)