Skip to content

Commit

Permalink
Add test to ensure that users can suppress internal warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Sep 4, 2018
1 parent 9965ed8 commit 60499d2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions testing/test_warnings.py
Expand Up @@ -349,6 +349,46 @@ def test_foo():
)


@pytest.mark.filterwarnings("default")
@pytest.mark.parametrize("ignore_pytest_warnings", ["no", "ini", "cmdline"])
def test_hide_pytest_internal_warnings(testdir, ignore_pytest_warnings):
"""Make sure we can ignore internal pytest warnings using a warnings filter."""
testdir.makepyfile(
"""
import pytest
import warnings
warnings.warn(pytest.PytestWarning("some internal warning"))
def test_bar():
pass
"""
)
if ignore_pytest_warnings == "ini":
testdir.makeini(
"""
[pytest]
filterwarnings = ignore::pytest.PytestWarning
"""
)
args = (
["-W", "ignore::pytest.PytestWarning"]
if ignore_pytest_warnings == "cmdline"
else []
)
result = testdir.runpytest(*args)
if ignore_pytest_warnings != "no":
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
else:
result.stdout.fnmatch_lines(
[
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
"*test_hide_pytest_internal_warnings.py:4: PytestWarning: some internal warning",
"* 1 passed, 1 warnings *",
]
)


class TestDeprecationWarningsByDefault:
"""
Note: all pytest runs are executed in a subprocess so we don't inherit warning filters
Expand Down

0 comments on commit 60499d2

Please sign in to comment.