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

Method pytest_collection_modifyitems

src/_pytest/stepwise.py:129–172  ·  src/_pytest/stepwise.py::StepwisePlugin.pytest_collection_modifyitems
(
        self, config: Config, items: list[nodes.Item]
    )

Source from the content-addressed store, hash-verified

127 self.session = session
128
129 def pytest_collection_modifyitems(
130 self, config: Config, items: list[nodes.Item]
131 ) -> None:
132 last_test_count = self.cached_info.last_test_count
133 self.cached_info.last_test_count = len(items)
134
135 if self.reset:
136 self.report_status.append(class="st">"resetting state, not skipping.")
137 self.cached_info.last_failed = None
138 return
139
140 if not self.cached_info.last_failed:
141 self.report_status.append(class="st">"no previously failed tests, not skipping.")
142 return
143
144 if last_test_count is not None and last_test_count != len(items):
145 self.report_status.append(
146 fclass="st">"test count changed, not skipping (now {len(items)} tests, previously {last_test_count})."
147 )
148 self.cached_info.last_failed = None
149 return
150
151 class="cm"># Check all item nodes until we find a match on last failed.
152 failed_index = None
153 for index, item in enumerate(items):
154 if item.nodeid == self.cached_info.last_failed:
155 failed_index = index
156 break
157
158 class="cm"># If the previously failed test was not found among the test items,
159 class="cm"># do not skip any tests.
160 if failed_index is None:
161 self.report_status.append(class="st">"previously failed test not found, not skipping.")
162 else:
163 cache_age = datetime.now() - self.cached_info.last_cache_date
164 class="cm"># Round up to avoid showing microseconds.
165 cache_age = timedelta(seconds=int(cache_age.total_seconds()))
166 self.report_status.append(
167 fclass="st">"skipping {failed_index} already passed items (cache from {cache_age} ago,"
168 fclass="st">" use --sw-reset to discard)."
169 )
170 deselected = items[:failed_index]
171 del items[:failed_index]
172 config.hook.pytest_deselected(items=deselected)
173
174 def pytest_runtest_logreport(self, report: TestReport) -> None:
175 if report.failed:

Callers

nothing calls this directly

Calls 3

intClass · 0.85
appendMethod · 0.80
pytest_deselectedMethod · 0.80

Tested by

no test coverage detected