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

Method pop

src/_pytest/recwarn.py:211–228  ·  src/_pytest/recwarn.py::WarningsRecorder.pop

Pop the first recorded warning which is an instance of ``cls``, but not an instance of a child class of any other match. Raises ``AssertionError`` if there is no match.

(self, cls: type[Warning] = Warning)

Source from the content-addressed store, hash-verified

209 return len(self._list)
210
211 def pop(self, cls: type[Warning] = Warning) -> warnings.WarningMessage:
212 class="st">"""Pop the first recorded warning which is an instance of ``cls``,
213 but not an instance of a child class of any other match.
214 Raises ``AssertionError`` if there is no match.
215 class="st">"""
216 best_idx: int | None = None
217 for i, w in enumerate(self._list):
218 if w.category == cls:
219 return self._list.pop(i) class="cm"># exact match, stop looking
220 if issubclass(w.category, cls) and (
221 best_idx is None
222 or not issubclass(w.category, self._list[best_idx].category)
223 ):
224 best_idx = i
225 if best_idx is not None:
226 return self._list.pop(best_idx)
227 __tracebackhide__ = True
228 raise AssertionError(fclass="st">"{cls!r} not found in warning list")
229
230 def clear(self) -> None:
231 class="st">""class="st">"Clear the list of recorded warnings."class="st">""

Callers 15

test_recordingMethod · 0.95
warnsFunction · 0.80
finalizeMethod · 0.80
insert_missing_modulesFunction · 0.80
compute_module_nameFunction · 0.80
assert_containsMethod · 0.80
inline_runMethod · 0.80
runpytest_inprocessMethod · 0.80
_match_linesMethod · 0.80
pytest_collectreportMethod · 0.80
rewriteMethod · 0.80

Calls

no outgoing calls