MCPcopy Create free account
hub / github.com/pytest-dev/pytest / pytest_collection_modifyitems

Function pytest_collection_modifyitems

testing/conftest.py:24–64  ·  view source on GitHub ↗

Prefer faster tests. Use a hookwrapper to do this in the beginning, so e.g. --ff still works correctly.

(items)

Source from the content-addressed store, hash-verified

22
23@pytest.hookimpl(hookwrapper=True, tryfirst=True)
24def pytest_collection_modifyitems(items):
25 """Prefer faster tests.
26
27 Use a hookwrapper to do this in the beginning, so e.g. --ff still works
28 correctly.
29 """
30 fast_items = []
31 slow_items = []
32 slowest_items = []
33 neutral_items = []
34
35 spawn_names = {"spawn_pytest", "spawn"}
36
37 for item in items:
38 try:
39 fixtures = item.fixturenames
40 except AttributeError:
41 # doctest at least
42 # (https://github.com/pytest-dev/pytest/issues/5070)
43 neutral_items.append(item)
44 else:
45 if "pytester" in fixtures:
46 co_names = item.function.__code__.co_names
47 if spawn_names.intersection(co_names):
48 item.add_marker(pytest.mark.uses_pexpect)
49 slowest_items.append(item)
50 elif "runpytest_subprocess" in co_names:
51 slowest_items.append(item)
52 else:
53 slow_items.append(item)
54 item.add_marker(pytest.mark.slow)
55 else:
56 marker = item.get_closest_marker("slow")
57 if marker:
58 slowest_items.append(item)
59 else:
60 fast_items.append(item)
61
62 items[:] = fast_items + neutral_items + slow_items + slowest_items
63
64 yield
65
66
67@pytest.fixture

Callers

nothing calls this directly

Calls 3

appendMethod · 0.80
add_markerMethod · 0.80
get_closest_markerMethod · 0.80

Tested by

no test coverage detected