MCPcopy
hub / github.com/pytest-dev/pytest / pytest_collection_modifyitems

Function pytest_collection_modifyitems

testing/conftest.py:51–91  ·  testing/conftest.py::pytest_collection_modifyitems

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

(items)

Source from the content-addressed store, hash-verified

49
50@pytest.hookimpl(wrapper=True, tryfirst=True)
51def pytest_collection_modifyitems(items) -> Generator[None]:
52 class="st">"""Prefer faster tests.
53
54 Use a hook wrapper to do this in the beginning, so e.g. --ff still works
55 correctly.
56 class="st">"""
57 fast_items = []
58 slow_items = []
59 slowest_items = []
60 neutral_items = []
61
62 spawn_names = {class="st">"spawn_pytest", class="st">"spawn"}
63
64 for item in items:
65 try:
66 fixtures = item.fixturenames
67 except AttributeError:
68 class="cm"># doctest at least
69 class="cm"># (https://github.com/pytest-dev/pytest/issues/5070)
70 neutral_items.append(item)
71 else:
72 if class="st">"pytester" in fixtures:
73 co_names = item.function.__code__.co_names
74 if spawn_names.intersection(co_names):
75 item.add_marker(pytest.mark.uses_pexpect)
76 slowest_items.append(item)
77 elif class="st">"runpytest_subprocess" in co_names:
78 slowest_items.append(item)
79 else:
80 slow_items.append(item)
81 item.add_marker(pytest.mark.slow)
82 else:
83 marker = item.get_closest_marker(class="st">"slow")
84 if marker:
85 slowest_items.append(item)
86 else:
87 fast_items.append(item)
88
89 items[:] = fast_items + neutral_items + slow_items + slowest_items
90
91 return (yield)
92
93
94@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