2017-05-25 17:59:42 +08:00
|
|
|
# -*- coding: utf8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-05-26 13:12:02 +08:00
|
|
|
import sys
|
|
|
|
|
2016-11-21 18:26:43 +08:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
WARNINGS_SUMMARY_HEADER = "warnings summary"
|
2017-02-25 23:02:48 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2016-11-21 18:26:43 +08:00
|
|
|
@pytest.fixture
|
2017-03-05 07:53:42 +08:00
|
|
|
def pyfile_with_warnings(testdir, request):
|
|
|
|
"""
|
|
|
|
Create a test file which calls a function in a module which generates warnings.
|
|
|
|
"""
|
|
|
|
testdir.syspathinsert()
|
|
|
|
test_name = request.function.__name__
|
2018-05-23 22:48:46 +08:00
|
|
|
module_name = test_name.lstrip("test_") + "_module"
|
|
|
|
testdir.makepyfile(
|
|
|
|
**{
|
|
|
|
module_name: """
|
2017-03-05 07:53:42 +08:00
|
|
|
import warnings
|
|
|
|
def foo():
|
2017-05-30 05:59:34 +08:00
|
|
|
warnings.warn(UserWarning("user warning"))
|
|
|
|
warnings.warn(RuntimeWarning("runtime warning"))
|
2017-03-05 07:53:42 +08:00
|
|
|
return 1
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
test_name: """
|
2017-03-05 07:53:42 +08:00
|
|
|
import {module_name}
|
|
|
|
def test_func():
|
|
|
|
assert {module_name}.foo() == 1
|
2018-05-23 22:48:46 +08:00
|
|
|
""".format(
|
|
|
|
module_name=module_name
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
2016-11-21 18:26:43 +08:00
|
|
|
|
|
|
|
|
2018-09-02 08:58:48 +08:00
|
|
|
@pytest.mark.filterwarnings("default")
|
2016-11-21 18:26:43 +08:00
|
|
|
def test_normal_flow(testdir, pyfile_with_warnings):
|
2017-03-05 07:53:42 +08:00
|
|
|
"""
|
2018-09-04 07:13:41 +08:00
|
|
|
Check that the warnings section is displayed.
|
2017-03-05 07:53:42 +08:00
|
|
|
"""
|
2017-02-18 22:57:26 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
|
|
|
|
"*normal_flow_module.py:3: UserWarning: user warning",
|
|
|
|
'* warnings.warn(UserWarning("user warning"))',
|
|
|
|
"*normal_flow_module.py:4: RuntimeWarning: runtime warning",
|
|
|
|
'* warnings.warn(RuntimeWarning("runtime warning"))',
|
|
|
|
"* 1 passed, 2 warnings*",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.filterwarnings("always")
|
2017-03-05 03:07:37 +08:00
|
|
|
def test_setup_teardown_warnings(testdir, pyfile_with_warnings):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-03-05 03:07:37 +08:00
|
|
|
import warnings
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def fix():
|
|
|
|
warnings.warn(UserWarning("warning during setup"))
|
|
|
|
yield
|
|
|
|
warnings.warn(UserWarning("warning during teardown"))
|
|
|
|
|
|
|
|
def test_func(fix):
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2017-03-05 03:07:37 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
|
|
|
|
"*test_setup_teardown_warnings.py:6: UserWarning: warning during setup",
|
|
|
|
'*warnings.warn(UserWarning("warning during setup"))',
|
|
|
|
"*test_setup_teardown_warnings.py:8: UserWarning: warning during teardown",
|
|
|
|
'*warnings.warn(UserWarning("warning during teardown"))',
|
|
|
|
"* 1 passed, 2 warnings*",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("method", ["cmdline", "ini"])
|
2016-11-21 18:26:43 +08:00
|
|
|
def test_as_errors(testdir, pyfile_with_warnings, method):
|
2018-05-23 22:48:46 +08:00
|
|
|
args = ("-W", "error") if method == "cmdline" else ()
|
|
|
|
if method == "ini":
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2016-11-21 18:26:43 +08:00
|
|
|
[pytest]
|
|
|
|
filterwarnings= error
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2017-02-18 22:57:26 +08:00
|
|
|
result = testdir.runpytest(*args)
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"E UserWarning: user warning",
|
|
|
|
"as_errors_module.py:3: UserWarning",
|
|
|
|
"* 1 failed in *",
|
|
|
|
]
|
|
|
|
)
|
2016-11-21 18:26:43 +08:00
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.parametrize("method", ["cmdline", "ini"])
|
2016-11-21 18:26:43 +08:00
|
|
|
def test_ignore(testdir, pyfile_with_warnings, method):
|
2018-05-23 22:48:46 +08:00
|
|
|
args = ("-W", "ignore") if method == "cmdline" else ()
|
|
|
|
if method == "ini":
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2016-11-21 18:26:43 +08:00
|
|
|
[pytest]
|
|
|
|
filterwarnings= ignore
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2016-11-21 18:26:43 +08:00
|
|
|
|
2017-02-18 22:57:26 +08:00
|
|
|
result = testdir.runpytest(*args)
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(["* 1 passed in *"])
|
2017-02-25 23:02:48 +08:00
|
|
|
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
|
2016-11-21 18:26:43 +08:00
|
|
|
|
2017-05-25 17:59:42 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
sys.version_info < (3, 0), reason="warnings message is unicode is ok in python3"
|
|
|
|
)
|
|
|
|
@pytest.mark.filterwarnings("always")
|
2017-05-25 17:59:42 +08:00
|
|
|
def test_unicode(testdir, pyfile_with_warnings):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-05-25 17:59:42 +08:00
|
|
|
# -*- coding: utf8 -*-
|
|
|
|
import warnings
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def fix():
|
|
|
|
warnings.warn(u"测试")
|
|
|
|
yield
|
|
|
|
|
|
|
|
def test_func(fix):
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2017-05-25 17:59:42 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
|
|
|
|
"*test_unicode.py:8: UserWarning: \u6d4b\u8bd5*",
|
|
|
|
"* 1 passed, 1 warnings*",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(
|
|
|
|
sys.version_info >= (3, 0),
|
|
|
|
reason="warnings message is broken as it is not str instance",
|
|
|
|
)
|
2017-05-26 13:12:02 +08:00
|
|
|
def test_py2_unicode(testdir, pyfile_with_warnings):
|
2018-06-26 21:35:27 +08:00
|
|
|
if getattr(sys, "pypy_version_info", ())[:2] == (5, 9) and sys.platform.startswith(
|
|
|
|
"win"
|
2018-05-23 22:48:46 +08:00
|
|
|
):
|
2017-11-10 05:14:20 +08:00
|
|
|
pytest.xfail("fails with unicode error on PyPy2 5.9 and Windows (#2905)")
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-05-26 13:12:02 +08:00
|
|
|
# -*- coding: utf8 -*-
|
|
|
|
import warnings
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def fix():
|
|
|
|
warnings.warn(u"测试")
|
|
|
|
yield
|
|
|
|
|
2017-07-21 10:11:14 +08:00
|
|
|
@pytest.mark.filterwarnings('always')
|
2017-05-26 13:12:02 +08:00
|
|
|
def test_func(fix):
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2017-05-26 13:12:02 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
|
|
|
|
"*test_py2_unicode.py:8: UserWarning: \\u6d4b\\u8bd5",
|
|
|
|
'*warnings.warn(u"\u6d4b\u8bd5")',
|
|
|
|
"*warnings.py:*: UnicodeWarning: Warning is using unicode non*",
|
|
|
|
"* 1 passed, 2 warnings*",
|
|
|
|
]
|
|
|
|
)
|
2017-05-30 05:59:34 +08:00
|
|
|
|
|
|
|
|
2017-10-03 03:20:51 +08:00
|
|
|
def test_py2_unicode_ascii(testdir):
|
|
|
|
"""Ensure that our warning about 'unicode warnings containing non-ascii messages'
|
|
|
|
does not trigger with ascii-convertible messages"""
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeini("[pytest]")
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-10-03 03:20:51 +08:00
|
|
|
import pytest
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
@pytest.mark.filterwarnings('always')
|
|
|
|
def test_func():
|
|
|
|
warnings.warn(u"hello")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2017-10-03 03:20:51 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
|
|
|
|
'*warnings.warn(u"hello")',
|
|
|
|
"* 1 passed, 1 warnings in*",
|
|
|
|
]
|
|
|
|
)
|
2017-10-03 03:20:51 +08:00
|
|
|
|
|
|
|
|
2017-05-30 05:59:34 +08:00
|
|
|
def test_works_with_filterwarnings(testdir):
|
|
|
|
"""Ensure our warnings capture does not mess with pre-installed filters (#2430)."""
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-05-30 05:59:34 +08:00
|
|
|
import warnings
|
|
|
|
|
|
|
|
class MyWarning(Warning):
|
|
|
|
pass
|
2017-07-17 07:25:06 +08:00
|
|
|
|
2017-05-30 05:59:34 +08:00
|
|
|
warnings.filterwarnings("error", category=MyWarning)
|
2017-07-17 07:25:06 +08:00
|
|
|
|
2017-05-30 05:59:34 +08:00
|
|
|
class TestWarnings(object):
|
|
|
|
def test_my_warning(self):
|
|
|
|
try:
|
|
|
|
warnings.warn(MyWarning("warn!"))
|
|
|
|
assert False
|
|
|
|
except MyWarning:
|
|
|
|
assert True
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2017-05-30 05:59:34 +08:00
|
|
|
result = testdir.runpytest()
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(["*== 1 passed in *"])
|
2017-07-21 09:02:21 +08:00
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.parametrize("default_config", ["ini", "cmdline"])
|
2017-07-21 09:02:21 +08:00
|
|
|
def test_filterwarnings_mark(testdir, default_config):
|
|
|
|
"""
|
|
|
|
Test ``filterwarnings`` mark works and takes precedence over command line and ini options.
|
|
|
|
"""
|
2018-05-23 22:48:46 +08:00
|
|
|
if default_config == "ini":
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
2017-07-21 09:02:21 +08:00
|
|
|
[pytest]
|
|
|
|
filterwarnings = always
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-07-21 09:02:21 +08:00
|
|
|
import warnings
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
@pytest.mark.filterwarnings('ignore::RuntimeWarning')
|
|
|
|
def test_ignore_runtime_warning():
|
|
|
|
warnings.warn(RuntimeWarning())
|
|
|
|
|
|
|
|
@pytest.mark.filterwarnings('error')
|
|
|
|
def test_warning_error():
|
|
|
|
warnings.warn(RuntimeWarning())
|
|
|
|
|
|
|
|
def test_show_warning():
|
|
|
|
warnings.warn(RuntimeWarning())
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("-W always" if default_config == "cmdline" else "")
|
|
|
|
result.stdout.fnmatch_lines(["*= 1 failed, 2 passed, 1 warnings in *"])
|
2017-11-28 09:07:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_non_string_warning_argument(testdir):
|
|
|
|
"""Non-str argument passed to warning breaks pytest (#2956)"""
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-11-28 09:07:29 +08:00
|
|
|
import warnings
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
def test():
|
|
|
|
warnings.warn(UserWarning(1, u'foo'))
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("-W", "always")
|
|
|
|
result.stdout.fnmatch_lines(["*= 1 passed, 1 warnings in *"])
|
2018-08-15 05:07:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_filterwarnings_mark_registration(testdir):
|
|
|
|
"""Ensure filterwarnings mark is registered"""
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
@pytest.mark.filterwarnings('error')
|
2018-08-15 09:29:42 +08:00
|
|
|
def test_func():
|
|
|
|
pass
|
2018-08-15 05:07:29 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("--strict")
|
|
|
|
assert result.ret == 0
|
2018-08-26 07:41:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.filterwarnings("always")
|
2018-09-05 02:22:07 +08:00
|
|
|
def test_warning_captured_hook(testdir):
|
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
|
|
|
from _pytest.warnings import _issue_config_warning
|
|
|
|
def pytest_configure(config):
|
|
|
|
_issue_config_warning(UserWarning("config warning"), config)
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
|
|
|
import pytest, warnings
|
|
|
|
|
|
|
|
warnings.warn(UserWarning("collect warning"))
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def fix():
|
|
|
|
warnings.warn(UserWarning("setup warning"))
|
|
|
|
yield 1
|
|
|
|
warnings.warn(UserWarning("teardown warning"))
|
|
|
|
|
|
|
|
def test_func(fix):
|
|
|
|
warnings.warn(UserWarning("call warning"))
|
|
|
|
assert fix == 1
|
|
|
|
"""
|
|
|
|
)
|
2018-08-26 07:41:16 +08:00
|
|
|
|
|
|
|
collected = []
|
|
|
|
|
|
|
|
class WarningCollector:
|
2018-08-26 09:15:22 +08:00
|
|
|
def pytest_warning_captured(self, warning_message, when, item):
|
2018-09-05 02:22:07 +08:00
|
|
|
imge_name = item.name if item is not None else ""
|
|
|
|
collected.append((str(warning_message.message), when, imge_name))
|
2018-08-26 07:41:16 +08:00
|
|
|
|
|
|
|
result = testdir.runpytest(plugins=[WarningCollector()])
|
|
|
|
result.stdout.fnmatch_lines(["*1 passed*"])
|
|
|
|
|
|
|
|
expected = [
|
2018-09-05 02:22:07 +08:00
|
|
|
("config warning", "config", ""),
|
|
|
|
("collect warning", "collect", ""),
|
|
|
|
("setup warning", "setup", "test_func"),
|
|
|
|
("call warning", "call", "test_func"),
|
|
|
|
("teardown warning", "teardown", "test_func"),
|
2018-08-26 07:41:16 +08:00
|
|
|
]
|
|
|
|
assert collected == expected
|
2018-08-26 22:09:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.filterwarnings("always")
|
|
|
|
def test_collection_warnings(testdir):
|
|
|
|
"""
|
2018-09-04 04:52:44 +08:00
|
|
|
Check that we also capture warnings issued during test collection (#3251).
|
2018-08-26 22:09:54 +08:00
|
|
|
"""
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
warnings.warn(UserWarning("collection warning"))
|
|
|
|
|
|
|
|
def test_foo():
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest()
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
|
|
|
|
"*collection_warnings.py:3: UserWarning: collection warning",
|
2018-09-04 07:13:41 +08:00
|
|
|
' warnings.warn(UserWarning("collection warning"))',
|
2018-08-26 22:09:54 +08:00
|
|
|
"* 1 passed, 1 warnings*",
|
|
|
|
]
|
|
|
|
)
|
2018-09-04 04:52:44 +08:00
|
|
|
|
|
|
|
|
2018-09-04 04:56:18 +08:00
|
|
|
@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 *",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-04 04:52:44 +08:00
|
|
|
class TestDeprecationWarningsByDefault:
|
|
|
|
"""
|
|
|
|
Note: all pytest runs are executed in a subprocess so we don't inherit warning filters
|
|
|
|
from pytest's own test suite
|
|
|
|
"""
|
|
|
|
|
|
|
|
def create_file(self, testdir, mark=""):
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
|
|
|
import pytest, warnings
|
|
|
|
|
|
|
|
warnings.warn(DeprecationWarning("collection"))
|
|
|
|
|
|
|
|
{mark}
|
|
|
|
def test_foo():
|
|
|
|
warnings.warn(PendingDeprecationWarning("test run"))
|
|
|
|
""".format(
|
|
|
|
mark=mark
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_shown_by_default(self, testdir):
|
|
|
|
self.create_file(testdir)
|
|
|
|
result = testdir.runpytest_subprocess()
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
|
|
|
|
"*test_shown_by_default.py:3: DeprecationWarning: collection",
|
|
|
|
"*test_shown_by_default.py:7: PendingDeprecationWarning: test run",
|
|
|
|
"* 1 passed, 2 warnings*",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_hidden_by_ini(self, testdir):
|
|
|
|
self.create_file(testdir)
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
|
|
|
[pytest]
|
|
|
|
filterwarnings = once::UserWarning
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest_subprocess()
|
|
|
|
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
|
|
|
|
|
|
|
|
def test_hidden_by_mark(self, testdir):
|
|
|
|
"""Should hide the deprecation warning from the function, but the warning during collection should
|
|
|
|
be displayed normally.
|
|
|
|
"""
|
|
|
|
self.create_file(
|
|
|
|
testdir, mark='@pytest.mark.filterwarnings("once::UserWarning")'
|
|
|
|
)
|
|
|
|
result = testdir.runpytest_subprocess()
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
|
|
|
|
"*test_hidden_by_mark.py:3: DeprecationWarning: collection",
|
|
|
|
"* 1 passed, 1 warnings*",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_hidden_by_cmdline(self, testdir):
|
|
|
|
self.create_file(testdir)
|
|
|
|
result = testdir.runpytest_subprocess("-W", "once::UserWarning")
|
|
|
|
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
|
|
|
|
|
|
|
|
def test_hidden_by_system(self, testdir, monkeypatch):
|
|
|
|
self.create_file(testdir)
|
|
|
|
monkeypatch.setenv(str("PYTHONWARNINGS"), str("once::UserWarning"))
|
|
|
|
result = testdir.runpytest_subprocess()
|
|
|
|
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
|