@@ -9,7 +9,6 @@ import py
|
||||
import pytest
|
||||
from _pytest.compat import importlib_metadata
|
||||
from _pytest.main import ExitCode
|
||||
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
|
||||
|
||||
|
||||
def prepend_pythonpath(*dirs):
|
||||
@@ -343,7 +342,7 @@ class TestGeneralUsage:
|
||||
"""
|
||||
)
|
||||
p = testdir.makepyfile("""def test_func(x): pass""")
|
||||
res = testdir.runpytest(p, SHOW_PYTEST_WARNINGS_ARG)
|
||||
res = testdir.runpytest(p)
|
||||
assert res.ret == 0
|
||||
res.stdout.fnmatch_lines(["*1 skipped*"])
|
||||
|
||||
@@ -356,9 +355,7 @@ class TestGeneralUsage:
|
||||
pass
|
||||
"""
|
||||
)
|
||||
res = testdir.runpytest(
|
||||
p.basename + "::" + "test_func[1]", SHOW_PYTEST_WARNINGS_ARG
|
||||
)
|
||||
res = testdir.runpytest(p.basename + "::" + "test_func[1]")
|
||||
assert res.ret == 0
|
||||
res.stdout.fnmatch_lines(["*1 passed*"])
|
||||
|
||||
|
||||
@@ -1,39 +1,5 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from _pytest import deprecated
|
||||
from _pytest.warning_types import PytestDeprecationWarning
|
||||
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
|
||||
|
||||
pytestmark = pytest.mark.pytester_example_path("deprecated")
|
||||
|
||||
|
||||
def test_pytest_setup_cfg_unsupported(testdir):
|
||||
testdir.makefile(
|
||||
".cfg",
|
||||
setup="""
|
||||
[pytest]
|
||||
addopts = --verbose
|
||||
""",
|
||||
)
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
testdir.runpytest()
|
||||
|
||||
|
||||
def test_pytest_custom_cfg_unsupported(testdir):
|
||||
testdir.makefile(
|
||||
".cfg",
|
||||
custom="""
|
||||
[pytest]
|
||||
addopts = --verbose
|
||||
""",
|
||||
)
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
testdir.runpytest("-c", "custom.cfg")
|
||||
|
||||
|
||||
def test_getfuncargvalue_is_deprecated(request):
|
||||
pytest.deprecated_call(request.getfuncargvalue, "tmpdir")
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("default")
|
||||
@@ -78,142 +44,3 @@ def test_external_plugins_integrated(testdir, plugin):
|
||||
|
||||
with pytest.warns(pytest.PytestConfigWarning):
|
||||
testdir.parseconfig("-p", plugin)
|
||||
|
||||
|
||||
def test_raises_message_argument_deprecated():
|
||||
with pytest.warns(pytest.PytestDeprecationWarning):
|
||||
with pytest.raises(RuntimeError, message="foobar"):
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
|
||||
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
||||
|
||||
testdir.makepyfile(
|
||||
**{
|
||||
"subdirectory/conftest.py": """
|
||||
pytest_plugins=['capture']
|
||||
"""
|
||||
}
|
||||
)
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_func():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
res = testdir.runpytest(SHOW_PYTEST_WARNINGS_ARG)
|
||||
assert res.ret == 2
|
||||
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
||||
res.stdout.fnmatch_lines(
|
||||
["*{msg}*".format(msg=msg), "*subdirectory{sep}conftest.py*".format(sep=os.sep)]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("use_pyargs", [True, False])
|
||||
def test_pytest_plugins_in_non_top_level_conftest_unsupported_pyargs(
|
||||
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 ()
|
||||
args += (SHOW_PYTEST_WARNINGS_ARG,)
|
||||
res = testdir.runpytest(*args)
|
||||
assert res.ret == (0 if use_pyargs else 2)
|
||||
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
||||
if use_pyargs:
|
||||
assert msg not in res.stdout.str()
|
||||
else:
|
||||
res.stdout.fnmatch_lines(["*{msg}*".format(msg=msg)])
|
||||
|
||||
|
||||
def test_pytest_plugins_in_non_top_level_conftest_unsupported_no_top_level_conftest(
|
||||
testdir
|
||||
):
|
||||
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
||||
|
||||
subdirectory = testdir.tmpdir.join("subdirectory")
|
||||
subdirectory.mkdir()
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
pytest_plugins=['capture']
|
||||
"""
|
||||
)
|
||||
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
||||
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_func():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
|
||||
res = testdir.runpytest_subprocess()
|
||||
assert res.ret == 2
|
||||
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
||||
res.stdout.fnmatch_lines(
|
||||
["*{msg}*".format(msg=msg), "*subdirectory{sep}conftest.py*".format(sep=os.sep)]
|
||||
)
|
||||
|
||||
|
||||
def test_pytest_plugins_in_non_top_level_conftest_unsupported_no_false_positives(
|
||||
testdir
|
||||
):
|
||||
from _pytest.deprecated import PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
||||
|
||||
subdirectory = testdir.tmpdir.join("subdirectory")
|
||||
subdirectory.mkdir()
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
pass
|
||||
"""
|
||||
)
|
||||
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
||||
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
import warnings
|
||||
warnings.filterwarnings('always', category=DeprecationWarning)
|
||||
pytest_plugins=['capture']
|
||||
"""
|
||||
)
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_func():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
res = testdir.runpytest_subprocess()
|
||||
assert res.ret == 0
|
||||
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
||||
assert msg not in res.stdout.str()
|
||||
|
||||
|
||||
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"
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_pytest_warns_unknown_kwargs():
|
||||
with pytest.warns(
|
||||
PytestDeprecationWarning,
|
||||
match=r"pytest.warns\(\) got unexpected keyword arguments: \['foo'\]",
|
||||
):
|
||||
pytest.warns(UserWarning, foo="hello")
|
||||
|
||||
+28
-47
@@ -7,7 +7,6 @@ from _pytest.fixtures import FixtureLookupError
|
||||
from _pytest.fixtures import FixtureRequest
|
||||
from _pytest.pathlib import Path
|
||||
from _pytest.pytester import get_public_names
|
||||
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
|
||||
|
||||
|
||||
def test_getfuncargnames():
|
||||
@@ -599,8 +598,7 @@ class TestRequestBasic:
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["* 2 passed in *"])
|
||||
|
||||
@pytest.mark.parametrize("getfixmethod", ("getfixturevalue", "getfuncargvalue"))
|
||||
def test_getfixturevalue(self, testdir, getfixmethod):
|
||||
def test_getfixturevalue(self, testdir):
|
||||
item = testdir.getitem(
|
||||
"""
|
||||
import pytest
|
||||
@@ -613,35 +611,22 @@ class TestRequestBasic:
|
||||
def test_func(something): pass
|
||||
"""
|
||||
)
|
||||
import contextlib
|
||||
|
||||
if getfixmethod == "getfuncargvalue":
|
||||
warning_expectation = pytest.warns(DeprecationWarning)
|
||||
else:
|
||||
# see #1830 for a cleaner way to accomplish this
|
||||
@contextlib.contextmanager
|
||||
def expecting_no_warning():
|
||||
yield
|
||||
|
||||
warning_expectation = expecting_no_warning()
|
||||
|
||||
req = item._request
|
||||
with warning_expectation:
|
||||
fixture_fetcher = getattr(req, getfixmethod)
|
||||
with pytest.raises(FixtureLookupError):
|
||||
fixture_fetcher("notexists")
|
||||
val = fixture_fetcher("something")
|
||||
assert val == 1
|
||||
val = fixture_fetcher("something")
|
||||
assert val == 1
|
||||
val2 = fixture_fetcher("other")
|
||||
assert val2 == 2
|
||||
val2 = fixture_fetcher("other") # see about caching
|
||||
assert val2 == 2
|
||||
pytest._fillfuncargs(item)
|
||||
assert item.funcargs["something"] == 1
|
||||
assert len(get_public_names(item.funcargs)) == 2
|
||||
assert "request" in item.funcargs
|
||||
|
||||
with pytest.raises(FixtureLookupError):
|
||||
req.getfixturevalue("notexists")
|
||||
val = req.getfixturevalue("something")
|
||||
assert val == 1
|
||||
val = req.getfixturevalue("something")
|
||||
assert val == 1
|
||||
val2 = req.getfixturevalue("other")
|
||||
assert val2 == 2
|
||||
val2 = req.getfixturevalue("other") # see about caching
|
||||
assert val2 == 2
|
||||
pytest._fillfuncargs(item)
|
||||
assert item.funcargs["something"] == 1
|
||||
assert len(get_public_names(item.funcargs)) == 2
|
||||
assert "request" in item.funcargs
|
||||
|
||||
def test_request_addfinalizer(self, testdir):
|
||||
item = testdir.getitem(
|
||||
@@ -1141,21 +1126,6 @@ class TestFixtureUsages:
|
||||
values = reprec.getfailedcollections()
|
||||
assert len(values) == 1
|
||||
|
||||
def test_request_can_be_overridden(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
@pytest.fixture()
|
||||
def request(request):
|
||||
request.a = 1
|
||||
return request
|
||||
def test_request(request):
|
||||
assert request.a == 1
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run("-Wignore::pytest.PytestDeprecationWarning")
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
def test_usefixtures_marker(self, testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
@@ -2200,7 +2170,7 @@ class TestFixtureMarker:
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest(SHOW_PYTEST_WARNINGS_ARG)
|
||||
result = testdir.runpytest()
|
||||
assert result.ret != 0
|
||||
result.stdout.fnmatch_lines(
|
||||
["*ScopeMismatch*You tried*function*session*request*"]
|
||||
@@ -3988,3 +3958,14 @@ def test_fixture_param_shadowing(testdir):
|
||||
result.stdout.fnmatch_lines(["*::test_normal_fixture[[]a[]]*"])
|
||||
result.stdout.fnmatch_lines(["*::test_normal_fixture[[]b[]]*"])
|
||||
result.stdout.fnmatch_lines(["*::test_indirect[[]1[]]*"])
|
||||
|
||||
|
||||
def test_fixture_named_request(testdir):
|
||||
testdir.copy_example("fixtures/test_fixture_named_request.py")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*'request' is a reserved word for fixtures, use another name:",
|
||||
" *test_fixture_named_request.py:5",
|
||||
]
|
||||
)
|
||||
|
||||
+13
-14
@@ -9,7 +9,6 @@ from hypothesis import strategies
|
||||
import pytest
|
||||
from _pytest import fixtures
|
||||
from _pytest import python
|
||||
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
|
||||
|
||||
|
||||
class TestMetafunc:
|
||||
@@ -915,7 +914,7 @@ class TestMetafuncFunctional:
|
||||
assert metafunc.cls == TestClass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest(p, "-v", SHOW_PYTEST_WARNINGS_ARG)
|
||||
result = testdir.runpytest(p, "-v")
|
||||
result.assert_outcomes(passed=2)
|
||||
|
||||
def test_two_functions(self, testdir):
|
||||
@@ -931,7 +930,7 @@ class TestMetafuncFunctional:
|
||||
assert arg1 in (10, 20)
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-v", p, SHOW_PYTEST_WARNINGS_ARG)
|
||||
result = testdir.runpytest("-v", p)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*test_func1*0*PASS*",
|
||||
@@ -967,7 +966,7 @@ class TestMetafuncFunctional:
|
||||
assert hello == "world"
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-v", p, SHOW_PYTEST_WARNINGS_ARG)
|
||||
result = testdir.runpytest("-v", p)
|
||||
result.stdout.fnmatch_lines(["*test_myfunc*hello*PASS*", "*1 passed*"])
|
||||
|
||||
def test_two_functions_not_same_instance(self, testdir):
|
||||
@@ -982,7 +981,7 @@ class TestMetafuncFunctional:
|
||||
self.x = 1
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-v", p, SHOW_PYTEST_WARNINGS_ARG)
|
||||
result = testdir.runpytest("-v", p)
|
||||
result.stdout.fnmatch_lines(
|
||||
["*test_func*0*PASS*", "*test_func*1*PASS*", "*2 pass*"]
|
||||
)
|
||||
@@ -1000,7 +999,7 @@ class TestMetafuncFunctional:
|
||||
self.val = 1
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest(p, SHOW_PYTEST_WARNINGS_ARG)
|
||||
result = testdir.runpytest(p)
|
||||
result.assert_outcomes(passed=1)
|
||||
|
||||
def test_parametrize_functional2(self, testdir):
|
||||
@@ -1522,7 +1521,7 @@ class TestMarkersWithParametrization:
|
||||
assert n + 1 == expected
|
||||
"""
|
||||
testdir.makepyfile(s)
|
||||
rec = testdir.inline_run("-m", "foo", SHOW_PYTEST_WARNINGS_ARG)
|
||||
rec = testdir.inline_run("-m", "foo")
|
||||
passed, skipped, fail = rec.listoutcomes()
|
||||
assert len(passed) == 1
|
||||
assert len(skipped) == 0
|
||||
@@ -1562,7 +1561,7 @@ class TestMarkersWithParametrization:
|
||||
assert n + 1 == expected
|
||||
"""
|
||||
testdir.makepyfile(s)
|
||||
reprec = testdir.inline_run(SHOW_PYTEST_WARNINGS_ARG)
|
||||
reprec = testdir.inline_run()
|
||||
# xfail is skip??
|
||||
reprec.assertoutcome(passed=2, skipped=1)
|
||||
|
||||
@@ -1579,7 +1578,7 @@ class TestMarkersWithParametrization:
|
||||
assert n % 2 == 0
|
||||
"""
|
||||
testdir.makepyfile(s)
|
||||
reprec = testdir.inline_run(SHOW_PYTEST_WARNINGS_ARG)
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=2, skipped=1)
|
||||
|
||||
def test_xfail_with_arg(self, testdir):
|
||||
@@ -1595,7 +1594,7 @@ class TestMarkersWithParametrization:
|
||||
assert n + 1 == expected
|
||||
"""
|
||||
testdir.makepyfile(s)
|
||||
reprec = testdir.inline_run(SHOW_PYTEST_WARNINGS_ARG)
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=2, skipped=1)
|
||||
|
||||
def test_xfail_with_kwarg(self, testdir):
|
||||
@@ -1611,7 +1610,7 @@ class TestMarkersWithParametrization:
|
||||
assert n + 1 == expected
|
||||
"""
|
||||
testdir.makepyfile(s)
|
||||
reprec = testdir.inline_run(SHOW_PYTEST_WARNINGS_ARG)
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=2, skipped=1)
|
||||
|
||||
def test_xfail_with_arg_and_kwarg(self, testdir):
|
||||
@@ -1627,7 +1626,7 @@ class TestMarkersWithParametrization:
|
||||
assert n + 1 == expected
|
||||
"""
|
||||
testdir.makepyfile(s)
|
||||
reprec = testdir.inline_run(SHOW_PYTEST_WARNINGS_ARG)
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=2, skipped=1)
|
||||
|
||||
@pytest.mark.parametrize("strict", [True, False])
|
||||
@@ -1648,7 +1647,7 @@ class TestMarkersWithParametrization:
|
||||
strict=strict
|
||||
)
|
||||
testdir.makepyfile(s)
|
||||
reprec = testdir.inline_run(SHOW_PYTEST_WARNINGS_ARG)
|
||||
reprec = testdir.inline_run()
|
||||
passed, failed = (2, 1) if strict else (3, 0)
|
||||
reprec.assertoutcome(passed=passed, failed=failed)
|
||||
|
||||
@@ -1672,7 +1671,7 @@ class TestMarkersWithParametrization:
|
||||
assert n + 1 == expected
|
||||
"""
|
||||
testdir.makepyfile(s)
|
||||
reprec = testdir.inline_run(SHOW_PYTEST_WARNINGS_ARG)
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=2, skipped=2)
|
||||
|
||||
def test_parametrize_ID_generation_string_int_works(self, testdir):
|
||||
|
||||
@@ -2,35 +2,20 @@ import sys
|
||||
|
||||
import pytest
|
||||
from _pytest.outcomes import Failed
|
||||
from _pytest.warning_types import PytestDeprecationWarning
|
||||
|
||||
|
||||
class TestRaises:
|
||||
def test_check_callable(self):
|
||||
with pytest.raises(TypeError, match=r".* must be callable"):
|
||||
pytest.raises(RuntimeError, "int('qwe')")
|
||||
|
||||
def test_raises(self):
|
||||
source = "int('qwe')"
|
||||
with pytest.warns(PytestDeprecationWarning):
|
||||
excinfo = pytest.raises(ValueError, source)
|
||||
code = excinfo.traceback[-1].frame.code
|
||||
s = str(code.fullsource)
|
||||
assert s == source
|
||||
|
||||
def test_raises_exec(self):
|
||||
with pytest.warns(PytestDeprecationWarning) as warninfo:
|
||||
pytest.raises(ValueError, "a,x = []")
|
||||
assert warninfo[0].filename == __file__
|
||||
|
||||
def test_raises_exec_correct_filename(self):
|
||||
with pytest.warns(PytestDeprecationWarning):
|
||||
excinfo = pytest.raises(ValueError, 'int("s")')
|
||||
assert __file__ in excinfo.traceback[-1].path
|
||||
|
||||
def test_raises_syntax_error(self):
|
||||
with pytest.warns(PytestDeprecationWarning) as warninfo:
|
||||
pytest.raises(SyntaxError, "qwe qwe qwe")
|
||||
assert warninfo[0].filename == __file__
|
||||
excinfo = pytest.raises(ValueError, int, "qwe")
|
||||
assert "invalid literal" in str(excinfo.value)
|
||||
|
||||
def test_raises_function(self):
|
||||
pytest.raises(ValueError, int, "hello")
|
||||
excinfo = pytest.raises(ValueError, int, "hello")
|
||||
assert "invalid literal" in str(excinfo.value)
|
||||
|
||||
def test_raises_callable_no_exception(self):
|
||||
class A:
|
||||
@@ -169,17 +154,6 @@ class TestRaises:
|
||||
else:
|
||||
assert False, "Expected pytest.raises.Exception"
|
||||
|
||||
def test_custom_raise_message(self):
|
||||
message = "TEST_MESSAGE"
|
||||
try:
|
||||
with pytest.warns(PytestDeprecationWarning):
|
||||
with pytest.raises(ValueError, message=message):
|
||||
pass
|
||||
except pytest.raises.Exception as e:
|
||||
assert e.msg == message
|
||||
else:
|
||||
assert False, "Expected pytest.raises.Exception"
|
||||
|
||||
@pytest.mark.parametrize("method", ["function", "with"])
|
||||
def test_raises_cyclic_reference(self, method):
|
||||
"""
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
@@ -1241,3 +1242,140 @@ def test_config_blocked_default_plugins(testdir, plugin):
|
||||
result.stdout.fnmatch_lines(["* 1 failed in *"])
|
||||
else:
|
||||
assert result.stdout.lines == [""]
|
||||
|
||||
|
||||
class TestSetupCfg:
|
||||
def test_pytest_setup_cfg_unsupported(self, testdir):
|
||||
testdir.makefile(
|
||||
".cfg",
|
||||
setup="""
|
||||
[pytest]
|
||||
addopts = --verbose
|
||||
""",
|
||||
)
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
testdir.runpytest()
|
||||
|
||||
def test_pytest_custom_cfg_unsupported(self, testdir):
|
||||
testdir.makefile(
|
||||
".cfg",
|
||||
custom="""
|
||||
[pytest]
|
||||
addopts = --verbose
|
||||
""",
|
||||
)
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
testdir.runpytest("-c", "custom.cfg")
|
||||
|
||||
|
||||
class TestPytestPluginsVariable:
|
||||
def test_pytest_plugins_in_non_top_level_conftest_unsupported(self, testdir):
|
||||
testdir.makepyfile(
|
||||
**{
|
||||
"subdirectory/conftest.py": """
|
||||
pytest_plugins=['capture']
|
||||
"""
|
||||
}
|
||||
)
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_func():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
res = testdir.runpytest()
|
||||
assert res.ret == 2
|
||||
msg = "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported"
|
||||
res.stdout.fnmatch_lines(
|
||||
[
|
||||
"*{msg}*".format(msg=msg),
|
||||
"*subdirectory{sep}conftest.py*".format(sep=os.sep),
|
||||
]
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize("use_pyargs", [True, False])
|
||||
def test_pytest_plugins_in_non_top_level_conftest_unsupported_pyargs(
|
||||
self, testdir, use_pyargs
|
||||
):
|
||||
"""When using --pyargs, do not emit the warning about non-top-level conftest warnings (#4039, #4044)"""
|
||||
|
||||
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 ()
|
||||
res = testdir.runpytest(*args)
|
||||
assert res.ret == (0 if use_pyargs else 2)
|
||||
msg = (
|
||||
msg
|
||||
) = "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported"
|
||||
if use_pyargs:
|
||||
assert msg not in res.stdout.str()
|
||||
else:
|
||||
res.stdout.fnmatch_lines(["*{msg}*".format(msg=msg)])
|
||||
|
||||
def test_pytest_plugins_in_non_top_level_conftest_unsupported_no_top_level_conftest(
|
||||
self, testdir
|
||||
):
|
||||
subdirectory = testdir.tmpdir.join("subdirectory")
|
||||
subdirectory.mkdir()
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
pytest_plugins=['capture']
|
||||
"""
|
||||
)
|
||||
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
||||
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_func():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
|
||||
res = testdir.runpytest_subprocess()
|
||||
assert res.ret == 2
|
||||
msg = "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported"
|
||||
res.stdout.fnmatch_lines(
|
||||
[
|
||||
"*{msg}*".format(msg=msg),
|
||||
"*subdirectory{sep}conftest.py*".format(sep=os.sep),
|
||||
]
|
||||
)
|
||||
|
||||
def test_pytest_plugins_in_non_top_level_conftest_unsupported_no_false_positives(
|
||||
self, testdir
|
||||
):
|
||||
subdirectory = testdir.tmpdir.join("subdirectory")
|
||||
subdirectory.mkdir()
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
pass
|
||||
"""
|
||||
)
|
||||
testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py"))
|
||||
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
import warnings
|
||||
warnings.filterwarnings('always', category=DeprecationWarning)
|
||||
pytest_plugins=['capture']
|
||||
"""
|
||||
)
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_func():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
res = testdir.runpytest_subprocess()
|
||||
assert res.ret == 0
|
||||
msg = "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported"
|
||||
assert msg not in res.stdout.str()
|
||||
|
||||
+5
-23
@@ -8,12 +8,6 @@ from _pytest.mark import EMPTY_PARAMETERSET_OPTION
|
||||
from _pytest.mark import MarkGenerator as Mark
|
||||
from _pytest.nodes import Collector
|
||||
from _pytest.nodes import Node
|
||||
from _pytest.warning_types import PytestDeprecationWarning
|
||||
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
|
||||
|
||||
ignore_markinfo = pytest.mark.filterwarnings(
|
||||
"ignore:MarkInfo objects:pytest.RemovedInPytest4Warning"
|
||||
)
|
||||
|
||||
|
||||
class TestMark:
|
||||
@@ -25,7 +19,8 @@ class TestMark:
|
||||
|
||||
def test_pytest_mark_notcallable(self):
|
||||
mark = Mark()
|
||||
pytest.raises((AttributeError, TypeError), mark)
|
||||
with pytest.raises(TypeError):
|
||||
mark()
|
||||
|
||||
def test_mark_with_param(self):
|
||||
def some_function(abc):
|
||||
@@ -625,7 +620,6 @@ class TestFunctional:
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
@ignore_markinfo
|
||||
def test_keyword_added_for_session(self, testdir):
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
@@ -651,7 +645,7 @@ class TestFunctional:
|
||||
assert marker.kwargs == {}
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run("-m", "mark1", SHOW_PYTEST_WARNINGS_ARG)
|
||||
reprec = testdir.inline_run("-m", "mark1")
|
||||
reprec.assertoutcome(passed=1)
|
||||
|
||||
def assert_markers(self, items, **expected):
|
||||
@@ -689,7 +683,7 @@ class TestFunctional:
|
||||
assert True
|
||||
"""
|
||||
)
|
||||
reprec = testdir.inline_run(SHOW_PYTEST_WARNINGS_ARG)
|
||||
reprec = testdir.inline_run()
|
||||
reprec.assertoutcome(skipped=1)
|
||||
|
||||
|
||||
@@ -989,7 +983,7 @@ def test_markers_from_parametrize(testdir):
|
||||
"""
|
||||
)
|
||||
|
||||
result = testdir.runpytest(SHOW_PYTEST_WARNINGS_ARG)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=4)
|
||||
|
||||
|
||||
@@ -1003,15 +997,3 @@ def test_pytest_param_id_requires_string():
|
||||
@pytest.mark.parametrize("s", (None, "hello world"))
|
||||
def test_pytest_param_id_allows_none_or_string(s):
|
||||
assert pytest.param(id=s)
|
||||
|
||||
|
||||
def test_pytest_param_warning_on_unknown_kwargs():
|
||||
with pytest.warns(PytestDeprecationWarning) as warninfo:
|
||||
# typo, should be marks=
|
||||
pytest.param(1, 2, mark=pytest.mark.xfail())
|
||||
assert warninfo[0].filename == __file__
|
||||
msg, = warninfo[0].message.args
|
||||
assert msg == (
|
||||
"pytest.param() got unexpected keyword arguments: ['mark'].\n"
|
||||
"This will be an error in future versions."
|
||||
)
|
||||
|
||||
@@ -72,8 +72,7 @@ def test_make_hook_recorder(testdir):
|
||||
def test_parseconfig(testdir):
|
||||
config1 = testdir.parseconfig()
|
||||
config2 = testdir.parseconfig()
|
||||
assert config2 != config1
|
||||
assert config1 != pytest.config
|
||||
assert config2 is not config1
|
||||
|
||||
|
||||
def test_testdir_runs_with_plugin(testdir):
|
||||
|
||||
+10
-16
@@ -3,7 +3,6 @@ import warnings
|
||||
|
||||
import pytest
|
||||
from _pytest.recwarn import WarningsRecorder
|
||||
from _pytest.warning_types import PytestDeprecationWarning
|
||||
|
||||
|
||||
def test_recwarn_stacklevel(recwarn):
|
||||
@@ -206,22 +205,17 @@ class TestDeprecatedCall:
|
||||
|
||||
|
||||
class TestWarns:
|
||||
def test_strings(self):
|
||||
def test_check_callable(self):
|
||||
source = "warnings.warn('w1', RuntimeWarning)"
|
||||
with pytest.raises(TypeError, match=r".* must be callable"):
|
||||
pytest.warns(RuntimeWarning, source)
|
||||
|
||||
def test_several_messages(self):
|
||||
# different messages, b/c Python suppresses multiple identical warnings
|
||||
source1 = "warnings.warn('w1', RuntimeWarning)"
|
||||
source2 = "warnings.warn('w2', RuntimeWarning)"
|
||||
source3 = "warnings.warn('w3', RuntimeWarning)"
|
||||
with pytest.warns(PytestDeprecationWarning) as warninfo: # yo dawg
|
||||
pytest.warns(RuntimeWarning, source1)
|
||||
pytest.raises(
|
||||
pytest.fail.Exception, lambda: pytest.warns(UserWarning, source2)
|
||||
)
|
||||
pytest.warns(RuntimeWarning, source3)
|
||||
assert len(warninfo) == 3
|
||||
for w in warninfo:
|
||||
assert w.filename == __file__
|
||||
msg, = w.message.args
|
||||
assert msg.startswith("warns(..., 'code(as_a_string)') is deprecated")
|
||||
pytest.warns(RuntimeWarning, lambda: warnings.warn("w1", RuntimeWarning))
|
||||
with pytest.raises(pytest.fail.Exception):
|
||||
pytest.warns(UserWarning, lambda: warnings.warn("w2", RuntimeWarning))
|
||||
pytest.warns(RuntimeWarning, lambda: warnings.warn("w3", RuntimeWarning))
|
||||
|
||||
def test_function(self):
|
||||
pytest.warns(
|
||||
|
||||
+4
-11
@@ -5,7 +5,6 @@ import attr
|
||||
import pytest
|
||||
from _pytest import pathlib
|
||||
from _pytest.pathlib import Path
|
||||
from _pytest.warnings import SHOW_PYTEST_WARNINGS_ARG
|
||||
|
||||
|
||||
def test_tmpdir_fixture(testdir):
|
||||
@@ -14,13 +13,6 @@ def test_tmpdir_fixture(testdir):
|
||||
results.stdout.fnmatch_lines(["*1 passed*"])
|
||||
|
||||
|
||||
def test_ensuretemp(recwarn):
|
||||
d1 = pytest.ensuretemp("hello")
|
||||
d2 = pytest.ensuretemp("hello")
|
||||
assert d1 == d2
|
||||
assert d1.check(dir=1)
|
||||
|
||||
|
||||
@attr.s
|
||||
class FakeConfig:
|
||||
basetemp = attr.ib()
|
||||
@@ -85,12 +77,13 @@ def test_basetemp(testdir):
|
||||
p = testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
def test_1():
|
||||
pytest.ensuretemp("hello")
|
||||
def test_1(tmpdir_factory):
|
||||
tmpdir_factory.mktemp('hello', numbered=False)
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest(p, "--basetemp=%s" % mytemp, SHOW_PYTEST_WARNINGS_ARG)
|
||||
result = testdir.runpytest(p, "--basetemp=%s" % mytemp)
|
||||
assert result.ret == 0
|
||||
print(mytemp)
|
||||
assert mytemp.join("hello").check()
|
||||
|
||||
|
||||
|
||||
@@ -498,38 +498,15 @@ class TestDeprecationWarningsByDefault:
|
||||
|
||||
|
||||
@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
|
||||
def test_removed_in_pytest4_warning_as_error(testdir, change_default):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import warnings, pytest
|
||||
def test():
|
||||
warnings.warn(pytest.RemovedInPytest4Warning("some warning"))
|
||||
"""
|
||||
)
|
||||
if change_default == "ini":
|
||||
testdir.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
filterwarnings =
|
||||
ignore::pytest.RemovedInPytest4Warning
|
||||
"""
|
||||
)
|
||||
|
||||
args = (
|
||||
("-Wignore::pytest.RemovedInPytest4Warning",)
|
||||
if change_default == "cmdline"
|
||||
else ()
|
||||
)
|
||||
result = testdir.runpytest(*args)
|
||||
if change_default is None:
|
||||
result.stdout.fnmatch_lines(["* 1 failed in *"])
|
||||
else:
|
||||
assert change_default in ("ini", "cmdline")
|
||||
result.stdout.fnmatch_lines(["* 1 passed in *"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
|
||||
@pytest.mark.skip(
|
||||
reason="This test should be enabled again before pytest 6.0 is released"
|
||||
)
|
||||
def test_deprecation_warning_as_error(testdir, change_default):
|
||||
"""This ensures that PytestDeprecationWarnings raised by pytest are turned into errors.
|
||||
|
||||
This test should be enabled as part of each major release, and skipped again afterwards
|
||||
to ensure our deprecations are turning into warnings as expected.
|
||||
"""
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import warnings, pytest
|
||||
|
||||
Reference in New Issue
Block a user