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

Method warn

src/_pytest/nodes.py:235–268  ·  src/_pytest/nodes.py::Node.warn

Issue a warning for this Node. Warnings will be displayed after the test session, unless explicitly suppressed. :param Warning warning: The warning instance to issue. :raises ValueError: If ``warning`` instance is not a subclass of Warning. Example usa

(self, warning: Warning)

Source from the content-addressed store, hash-verified

233 return class="st">"<{} {}>".format(self.__class__.__name__, getattr(self, class="st">"name", None))
234
235 def warn(self, warning: Warning) -> None:
236 class="st">"""Issue a warning for this Node.
237
238 Warnings will be displayed after the test session, unless explicitly suppressed.
239
240 :param Warning warning:
241 The warning instance to issue.
242
243 :raises ValueError: If ``warning`` instance is not a subclass of Warning.
244
245 Example usage:
246
247 .. code-block:: python
248
249 node.warn(PytestWarning(class="st">"some message"))
250 node.warn(UserWarning(class="st">"some message"))
251
252 .. versionchanged:: 6.2
253 Any subclass of :class:`Warning` is now accepted, rather than only
254 :class:`PytestWarning <pytest.PytestWarning>` subclasses.
255 class="st">"""
256 class="cm"># enforce type checks here to avoid getting a generic type error later otherwise.
257 if not isinstance(warning, Warning):
258 raise ValueError(
259 fclass="st">"warning must be an instance of Warning or subclass, got {warning!r}"
260 )
261 path, lineno = get_fslocation_from_item(self)
262 assert lineno is not None
263 warnings.warn_explicit(
264 warning,
265 category=None,
266 filename=str(path),
267 lineno=lineno + 1,
268 )
269
270 class="cm"># Methods for ordering nodes.
271

Callers 15

collect_unraisableFunction · 0.45
record_xml_attributeFunction · 0.45
__init__Method · 0.45
on_rm_rf_errorFunction · 0.45
_mock_aware_unwrapFunction · 0.45
collect_thread_exceptionFunction · 0.45
pytest_pyfunc_callFunction · 0.45
collectMethod · 0.45
__init__Method · 0.45

Calls 1

get_fslocation_from_itemFunction · 0.85