2018-10-25 15:01:29 +08:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
2018-07-22 22:10:44 +08:00
|
|
|
|
2018-09-02 04:10:26 +08:00
|
|
|
import os
|
2018-07-22 22:10:44 +08:00
|
|
|
|
2016-07-23 22:56:04 +08:00
|
|
|
import pytest
|
2019-02-06 05:14:02 +08:00
|
|
|
from _pytest.warning_types import PytestDeprecationWarning
|
2018-11-09 06:14:58 +08:00
|
|
|
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
|
2016-07-23 22:56:04 +08:00
|
|
|
|
2018-10-20 23:09:44 +08:00
|
|
|
pytestmark = pytest.mark.pytester_example_path("deprecated")
|
|
|
|
|
2016-07-23 22:56:04 +08:00
|
|
|
|
2018-12-20 03:43:17 +08:00
|
|
|
def test_pytest_setup_cfg_unsupported(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makefile(
|
|
|
|
".cfg",
|
|
|
|
setup="""
|
2016-08-17 08:30:07 +08:00
|
|
|
[pytest]
|
|
|
|
addopts = --verbose
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2018-12-20 03:43:17 +08:00
|
|
|
with pytest.raises(pytest.fail.Exception):
|
|
|
|
testdir.runpytest()
|
2016-08-17 08:30:07 +08:00
|
|
|
|
|
|
|
|
2018-12-20 03:43:17 +08:00
|
|
|
def test_pytest_custom_cfg_unsupported(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makefile(
|
|
|
|
".cfg",
|
|
|
|
custom="""
|
2018-03-02 15:52:38 +08:00
|
|
|
[pytest]
|
|
|
|
addopts = --verbose
|
2018-05-23 22:48:46 +08:00
|
|
|
""",
|
|
|
|
)
|
2018-12-20 03:43:17 +08:00
|
|
|
with pytest.raises(pytest.fail.Exception):
|
|
|
|
testdir.runpytest("-c", "custom.cfg")
|
2018-03-02 15:52:38 +08:00
|
|
|
|
|
|
|
|
2016-07-23 22:56:04 +08:00
|
|
|
def test_getfuncargvalue_is_deprecated(request):
|
2018-05-23 22:48:46 +08:00
|
|
|
pytest.deprecated_call(request.getfuncargvalue, "tmpdir")
|
2016-08-17 07:22:15 +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(
|
|
|
|
[
|
2018-11-23 07:14:53 +08:00
|
|
|
"*--result-log is deprecated and scheduled for removal in pytest 5.0*",
|
|
|
|
"*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
|
|
|
|
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
@pytest.mark.parametrize("plugin", ["catchlog", "capturelog"])
|
2018-12-12 06:02:36 +08:00
|
|
|
@pytest.mark.filterwarnings("default")
|
2017-12-06 03:02:56 +08:00
|
|
|
def test_pytest_catchlog_deprecated(testdir, plugin):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2017-11-24 05:34:52 +08:00
|
|
|
def test_func(pytestconfig):
|
2018-05-18 05:31:16 +08:00
|
|
|
pytestconfig.pluginmanager.register(None, 'pytest_{}')
|
2018-05-23 22:48:46 +08:00
|
|
|
""".format(
|
|
|
|
plugin
|
|
|
|
)
|
|
|
|
)
|
2017-11-24 05:34:52 +08:00
|
|
|
res = testdir.runpytest()
|
|
|
|
assert res.ret == 0
|
2018-05-23 22:48:46 +08:00
|
|
|
res.stdout.fnmatch_lines(
|
|
|
|
["*pytest-*log plugin has been merged into the core*", "*1 passed, 1 warnings*"]
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
|
|
|
|
|
2018-12-13 05:12:44 +08:00
|
|
|
def test_raises_message_argument_deprecated():
|
|
|
|
with pytest.warns(pytest.PytestDeprecationWarning):
|
|
|
|
with pytest.raises(RuntimeError, message="foobar"):
|
|
|
|
raise RuntimeError
|
|
|
|
|
|
|
|
|
2018-02-21 07:27:24 +08:00
|
|
|
def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
|
|
|
|
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2018-09-26 21:49:14 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
**{
|
|
|
|
"subdirectory/conftest.py": """
|
2018-02-21 07:27:24 +08:00
|
|
|
pytest_plugins=['capture']
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
2018-09-26 21:49:14 +08:00
|
|
|
}
|
2018-05-23 22:48:46 +08:00
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
def test_func():
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-11-09 06:14:58 +08:00
|
|
|
res = testdir.runpytest(SHOW_PYTEST_WARNINGS_ARG)
|
2018-12-20 04:09:47 +08:00
|
|
|
assert res.ret == 2
|
2018-09-05 03:29:48 +08:00
|
|
|
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
2018-09-02 04:10:26 +08:00
|
|
|
res.stdout.fnmatch_lines(
|
2018-12-20 04:09:47 +08:00
|
|
|
["*{msg}*".format(msg=msg), "*subdirectory{sep}conftest.py*".format(sep=os.sep)]
|
2018-05-23 22:48:46 +08:00
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
|
|
|
|
|
2018-09-26 23:00:49 +08:00
|
|
|
@pytest.mark.parametrize("use_pyargs", [True, False])
|
2018-12-20 04:09:47 +08:00
|
|
|
def test_pytest_plugins_in_non_top_level_conftest_unsupported_pyargs(
|
2018-09-26 23:00:49 +08:00
|
|
|
testdir, use_pyargs
|
|
|
|
):
|
|
|
|
"""When using --pyargs, do not emit the warning about non-top-level conftest warnings (#4039, #4044)"""
|
|
|
|
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
|
|
|
|
|
|
|
files = {
|
|
|
|
"src/pkg/__init__.py": "",
|
|
|
|
"src/pkg/conftest.py": "",
|
|
|
|
"src/pkg/test_root.py": "def test(): pass",
|
|
|
|
"src/pkg/sub/__init__.py": "",
|
|
|
|
"src/pkg/sub/conftest.py": "pytest_plugins=['capture']",
|
|
|
|
"src/pkg/sub/test_bar.py": "def test(): pass",
|
|
|
|
}
|
|
|
|
testdir.makepyfile(**files)
|
|
|
|
testdir.syspathinsert(testdir.tmpdir.join("src"))
|
|
|
|
|
|
|
|
args = ("--pyargs", "pkg") if use_pyargs else ()
|
2018-11-09 06:14:58 +08:00
|
|
|
args += (SHOW_PYTEST_WARNINGS_ARG,)
|
2018-09-26 23:00:49 +08:00
|
|
|
res = testdir.runpytest(*args)
|
2018-12-20 04:09:47 +08:00
|
|
|
assert res.ret == (0 if use_pyargs else 2)
|
2018-09-26 23:00:49 +08:00
|
|
|
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
|
|
|
if use_pyargs:
|
|
|
|
assert msg not in res.stdout.str()
|
|
|
|
else:
|
2019-03-23 18:36:18 +08:00
|
|
|
res.stdout.fnmatch_lines(["*{msg}*".format(msg=msg)])
|
2018-09-26 23:00:49 +08:00
|
|
|
|
|
|
|
|
2018-12-20 04:09:47 +08:00
|
|
|
def test_pytest_plugins_in_non_top_level_conftest_unsupported_no_top_level_conftest(
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir
|
|
|
|
):
|
2018-02-21 07:27:24 +08:00
|
|
|
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
2018-05-23 22:48:46 +08:00
|
|
|
|
|
|
|
subdirectory = testdir.tmpdir.join("subdirectory")
|
2018-02-21 07:27:24 +08:00
|
|
|
subdirectory.mkdir()
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
pytest_plugins=['capture']
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
def test_func():
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
|
|
|
|
res = testdir.runpytest_subprocess()
|
2018-12-20 04:09:47 +08:00
|
|
|
assert res.ret == 2
|
2018-09-05 03:29:48 +08:00
|
|
|
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
2018-09-02 04:10:26 +08:00
|
|
|
res.stdout.fnmatch_lines(
|
2018-12-20 04:09:47 +08:00
|
|
|
["*{msg}*".format(msg=msg), "*subdirectory{sep}conftest.py*".format(sep=os.sep)]
|
2018-05-23 22:48:46 +08:00
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
|
|
|
|
|
2018-12-20 04:09:47 +08:00
|
|
|
def test_pytest_plugins_in_non_top_level_conftest_unsupported_no_false_positives(
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir
|
|
|
|
):
|
2018-02-21 07:27:24 +08:00
|
|
|
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
2018-05-23 22:48:46 +08:00
|
|
|
|
|
|
|
subdirectory = testdir.tmpdir.join("subdirectory")
|
2018-02-21 07:27:24 +08:00
|
|
|
subdirectory.mkdir()
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
import warnings
|
|
|
|
warnings.filterwarnings('always', category=DeprecationWarning)
|
|
|
|
pytest_plugins=['capture']
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
testdir.makepyfile(
|
|
|
|
"""
|
2018-02-21 07:27:24 +08:00
|
|
|
def test_func():
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2018-02-21 07:27:24 +08:00
|
|
|
res = testdir.runpytest_subprocess()
|
|
|
|
assert res.ret == 0
|
2018-09-05 03:29:48 +08:00
|
|
|
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
2018-09-02 04:10:26 +08:00
|
|
|
assert msg not in res.stdout.str()
|
2018-07-22 22:10:44 +08:00
|
|
|
|
|
|
|
|
2018-10-20 23:09:44 +08:00
|
|
|
def test_fixture_named_request(testdir):
|
|
|
|
testdir.copy_example()
|
|
|
|
result = testdir.runpytest()
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
[
|
|
|
|
"*'request' is a reserved name for fixtures and will raise an error in future versions"
|
|
|
|
]
|
|
|
|
)
|
2019-01-30 01:31:20 +08:00
|
|
|
|
|
|
|
|
2019-02-06 05:14:02 +08:00
|
|
|
def test_pytest_warns_unknown_kwargs():
|
|
|
|
with pytest.warns(
|
|
|
|
PytestDeprecationWarning,
|
|
|
|
match=r"pytest.warns\(\) got unexpected keyword arguments: \['foo'\]",
|
|
|
|
):
|
|
|
|
pytest.warns(UserWarning, foo="hello")
|