2020-03-31 05:40:33 +08:00
|
|
|
import copy
|
2019-10-17 03:52:04 +08:00
|
|
|
import inspect
|
2020-04-17 21:05:43 +08:00
|
|
|
from unittest import mock
|
2019-10-17 03:52:04 +08:00
|
|
|
|
2016-07-23 22:56:04 +08:00
|
|
|
import pytest
|
2019-06-13 05:49:51 +08:00
|
|
|
from _pytest import deprecated
|
2019-10-17 03:52:04 +08:00
|
|
|
from _pytest import nodes
|
2020-03-31 05:40:33 +08:00
|
|
|
from _pytest.config import Config
|
2016-07-23 22:56:04 +08:00
|
|
|
|
|
|
|
|
2018-09-02 08:58:48 +08:00
|
|
|
@pytest.mark.filterwarnings("default")
|
2016-08-17 07:22:15 +08:00
|
|
|
def test_resultlog_is_deprecated(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
result = testdir.runpytest("--help")
|
|
|
|
result.stdout.fnmatch_lines(["*DEPRECATED path for machine-readable result log*"])
|
2016-08-17 07:22:15 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2016-08-17 07:22:15 +08:00
|
|
|
def test():
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("--result-log=%s" % testdir.tmpdir.join("result.log"))
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
2019-11-15 05:26:49 +08:00
|
|
|
"*--result-log is deprecated, please try the new pytest-reportlog plugin.",
|
2018-11-23 07:14:53 +08:00
|
|
|
"*See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information*",
|
2018-05-23 22:48:46 +08:00
|
|
|
]
|
|
|
|
)
|
2017-11-15 23:48:08 +08:00
|
|
|
|
|
|
|
|
2020-03-30 02:30:16 +08:00
|
|
|
@pytest.mark.parametrize("attribute", pytest.collect.__all__) # type: ignore
|
|
|
|
# false positive due to dynamic attribute
|
|
|
|
def test_pytest_collect_module_deprecated(attribute):
|
|
|
|
with pytest.warns(DeprecationWarning, match=attribute):
|
|
|
|
getattr(pytest.collect, attribute)
|
|
|
|
|
|
|
|
|
2020-03-31 05:40:33 +08:00
|
|
|
def test_terminal_reporter_writer_attr(pytestconfig: Config) -> None:
|
2017-12-01 04:34:53 +08:00
|
|
|
"""Check that TerminalReporter._tw is also available as 'writer' (#2984)
|
2020-02-21 07:58:44 +08:00
|
|
|
This attribute has been deprecated in 5.4.
|
2017-12-01 04:34:53 +08:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
import xdist # noqa
|
2018-05-23 22:48:46 +08:00
|
|
|
|
|
|
|
pytest.skip("xdist workers disable the terminal reporter plugin")
|
2017-12-01 04:34:53 +08:00
|
|
|
except ImportError:
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
terminal_reporter = pytestconfig.pluginmanager.get_plugin("terminalreporter")
|
2020-03-31 05:40:33 +08:00
|
|
|
original_tw = terminal_reporter._tw
|
|
|
|
|
|
|
|
with pytest.warns(pytest.PytestDeprecationWarning) as cw:
|
|
|
|
assert terminal_reporter.writer is original_tw
|
|
|
|
assert len(cw) == 1
|
|
|
|
assert cw[0].filename == __file__
|
|
|
|
|
|
|
|
new_tw = copy.copy(original_tw)
|
|
|
|
with pytest.warns(pytest.PytestDeprecationWarning) as cw:
|
|
|
|
terminal_reporter.writer = new_tw
|
|
|
|
try:
|
|
|
|
assert terminal_reporter._tw is new_tw
|
|
|
|
finally:
|
|
|
|
terminal_reporter.writer = original_tw
|
|
|
|
assert len(cw) == 2
|
|
|
|
assert cw[0].filename == cw[1].filename == __file__
|
2017-12-01 04:34:53 +08:00
|
|
|
|
|
|
|
|
2019-07-06 06:04:55 +08:00
|
|
|
@pytest.mark.parametrize("plugin", sorted(deprecated.DEPRECATED_EXTERNAL_PLUGINS))
|
2018-12-12 06:02:36 +08:00
|
|
|
@pytest.mark.filterwarnings("default")
|
2019-06-13 05:49:51 +08:00
|
|
|
def test_external_plugins_integrated(testdir, plugin):
|
|
|
|
testdir.syspathinsert()
|
|
|
|
testdir.makepyfile(**{plugin: ""})
|
|
|
|
|
|
|
|
with pytest.warns(pytest.PytestConfigWarning):
|
|
|
|
testdir.parseconfig("-p", plugin)
|
2019-11-14 05:20:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("junit_family", [None, "legacy", "xunit2"])
|
|
|
|
def test_warn_about_imminent_junit_family_default_change(testdir, junit_family):
|
|
|
|
"""Show a warning if junit_family is not defined and --junitxml is used (#6179)"""
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
|
|
|
def test_foo():
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
if junit_family:
|
|
|
|
testdir.makeini(
|
|
|
|
"""
|
|
|
|
[pytest]
|
|
|
|
junit_family={junit_family}
|
|
|
|
""".format(
|
|
|
|
junit_family=junit_family
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
result = testdir.runpytest("--junit-xml=foo.xml")
|
|
|
|
warning_msg = (
|
|
|
|
"*PytestDeprecationWarning: The 'junit_family' default value will change*"
|
|
|
|
)
|
|
|
|
if junit_family:
|
|
|
|
result.stdout.no_fnmatch_line(warning_msg)
|
|
|
|
else:
|
|
|
|
result.stdout.fnmatch_lines([warning_msg])
|
2019-10-17 03:52:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_node_direct_ctor_warning():
|
|
|
|
class MockConfig:
|
|
|
|
pass
|
|
|
|
|
|
|
|
ms = MockConfig()
|
|
|
|
with pytest.warns(
|
|
|
|
DeprecationWarning,
|
2020-02-06 07:00:02 +08:00
|
|
|
match="Direct construction of .* has been deprecated, please use .*.from_parent.*",
|
2019-10-17 03:52:04 +08:00
|
|
|
) as w:
|
|
|
|
nodes.Node(name="test", config=ms, session=ms, nodeid="None")
|
|
|
|
assert w[0].lineno == inspect.currentframe().f_lineno - 1
|
|
|
|
assert w[0].filename == __file__
|
2019-12-11 11:47:51 +08:00
|
|
|
|
|
|
|
|
2020-04-17 21:05:43 +08:00
|
|
|
def test__fillfuncargs_is_deprecated() -> None:
|
|
|
|
with pytest.warns(
|
|
|
|
pytest.PytestDeprecationWarning,
|
|
|
|
match="The `_fillfuncargs` function is deprecated",
|
|
|
|
):
|
|
|
|
pytest._fillfuncargs(mock.Mock())
|
2020-05-11 20:44:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_minus_k_dash_is_deprecated(testdir) -> None:
|
|
|
|
threepass = testdir.makepyfile(
|
|
|
|
test_threepass="""
|
|
|
|
def test_one(): assert 1
|
|
|
|
def test_two(): assert 1
|
|
|
|
def test_three(): assert 1
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("-k=-test_two", threepass)
|
|
|
|
result.stdout.fnmatch_lines(["*The `-k '-expr'` syntax*deprecated*"])
|
|
|
|
|
|
|
|
|
|
|
|
def test_minus_k_colon_is_deprecated(testdir) -> None:
|
|
|
|
threepass = testdir.makepyfile(
|
|
|
|
test_threepass="""
|
|
|
|
def test_one(): assert 1
|
|
|
|
def test_two(): assert 1
|
|
|
|
def test_three(): assert 1
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
result = testdir.runpytest("-k", "test_two:", threepass)
|
|
|
|
result.stdout.fnmatch_lines(["*The `-k 'expr:'` syntax*deprecated*"])
|