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

Function test_collection_warnings

testing/test_warnings.py:303–323  ·  view source on GitHub ↗

Check that we also capture warnings issued during test collection (#3251).

(pytester: Pytester)

Source from the content-addressed store, hash-verified

301
302@pytest.mark.filterwarnings("always::UserWarning")
303def test_collection_warnings(pytester: Pytester) -> None:
304 """Check that we also capture warnings issued during test collection (#3251)."""
305 pytester.makepyfile(
306 """
307 import warnings
308
309 warnings.warn(UserWarning("collection warning"))
310
311 def test_foo():
312 pass
313 """
314 )
315 result = pytester.runpytest()
316 result.stdout.fnmatch_lines(
317 [
318 "*== %s ==*" % WARNINGS_SUMMARY_HEADER,
319 " *collection_warnings.py:3: UserWarning: collection warning",
320 ' warnings.warn(UserWarning("collection warning"))',
321 "* 1 passed, 1 warning*",
322 ]
323 )
324
325
326@pytest.mark.filterwarnings("always::UserWarning")

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected