Skip to content

Commit 60499d2

Browse files
committed
Add test to ensure that users can suppress internal warnings
1 parent 9965ed8 commit 60499d2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

testing/test_warnings.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,46 @@ def test_foo():
349349
)
350350

351351

352+
@pytest.mark.filterwarnings("default")
353+
@pytest.mark.parametrize("ignore_pytest_warnings", ["no", "ini", "cmdline"])
354+
def test_hide_pytest_internal_warnings(testdir, ignore_pytest_warnings):
355+
"""Make sure we can ignore internal pytest warnings using a warnings filter."""
356+
testdir.makepyfile(
357+
"""
358+
import pytest
359+
import warnings
360+
361+
warnings.warn(pytest.PytestWarning("some internal warning"))
362+
363+
def test_bar():
364+
pass
365+
"""
366+
)
367+
if ignore_pytest_warnings == "ini":
368+
testdir.makeini(
369+
"""
370+
[pytest]
371+
filterwarnings = ignore::pytest.PytestWarning
372+
"""
373+
)
374+
args = (
375+
["-W", "ignore::pytest.PytestWarning"]
376+
if ignore_pytest_warnings == "cmdline"
377+
else []
378+
)
379+
result = testdir.runpytest(*args)
380+
if ignore_pytest_warnings != "no":
381+
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
382+
else:
383+
result.stdout.fnmatch_lines(
384+
[
385+
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
386+
"*test_hide_pytest_internal_warnings.py:4: PytestWarning: some internal warning",
387+
"* 1 passed, 1 warnings *",
388+
]
389+
)
390+
391+
352392
class TestDeprecationWarningsByDefault:
353393
"""
354394
Note: all pytest runs are executed in a subprocess so we don't inherit warning filters

0 commit comments

Comments
 (0)