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

Function test_hide_pytest_internal_warnings

testing/test_warnings.py:344–381  ·  view source on GitHub ↗

Make sure we can ignore internal pytest warnings using a warnings filter.

(
    pytester: Pytester, ignore_pytest_warnings
)

Source from the content-addressed store, hash-verified

342@pytest.mark.filterwarnings("default::pytest.PytestWarning")
343@pytest.mark.parametrize("ignore_pytest_warnings", ["no", "ini", "cmdline"])
344def test_hide_pytest_internal_warnings(
345 pytester: Pytester, ignore_pytest_warnings
346) -> None:
347 """Make sure we can ignore internal pytest warnings using a warnings filter."""
348 pytester.makepyfile(
349 """
350 import pytest
351 import warnings
352
353 warnings.warn(pytest.PytestWarning("some internal warning"))
354
355 def test_bar():
356 pass
357 """
358 )
359 if ignore_pytest_warnings == "ini":
360 pytester.makeini(
361 """
362 [pytest]
363 filterwarnings = ignore::pytest.PytestWarning
364 """
365 )
366 args = (
367 ["-W", "ignore::pytest.PytestWarning"]
368 if ignore_pytest_warnings == "cmdline"
369 else []
370 )
371 result = pytester.runpytest(*args)
372 if ignore_pytest_warnings != "no":
373 assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
374 else:
375 result.stdout.fnmatch_lines(
376 [
377 "*== %s ==*" % WARNINGS_SUMMARY_HEADER,
378 "*test_hide_pytest_internal_warnings.py:4: PytestWarning: some internal warning",
379 "* 1 passed, 1 warning *",
380 ]
381 )
382
383
384@pytest.mark.parametrize("ignore_on_cmdline", [True, False])

Callers

nothing calls this directly

Calls 5

strMethod · 0.80
fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
makeiniMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected