2019-10-17 03:52:04 +08:00
|
|
|
import inspect
|
|
|
|
|
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
|
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
|
|
|
|
|
|
|
|
2017-12-01 04:34:53 +08:00
|
|
|
def test_terminal_reporter_writer_attr(pytestconfig):
|
|
|
|
"""Check that TerminalReporter._tw is also available as 'writer' (#2984)
|
|
|
|
This attribute is planned to be deprecated in 3.4.
|
|
|
|
"""
|
|
|
|
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")
|
2017-12-01 04:34:53 +08:00
|
|
|
assert terminal_reporter.writer is terminal_reporter._tw
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
match="direct construction of .* has been deprecated, please use .*.from_parent",
|
|
|
|
) 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__
|