Remove Request.getfuncargvalue
This commit is contained in:
parent
4f9bf028f5
commit
be91c4d932
|
@ -0,0 +1,4 @@
|
||||||
|
As per our policy, the following features have been deprecated in the 4.X series and are now being
|
||||||
|
removed:
|
||||||
|
|
||||||
|
* ``Request.getfuncargvalue``: use ``Request.getfixturevalue`` instead.
|
|
@ -36,9 +36,6 @@ FIXTURE_NAMED_REQUEST = PytestDeprecationWarning(
|
||||||
|
|
||||||
CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead."
|
CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead."
|
||||||
|
|
||||||
GETFUNCARGVALUE = RemovedInPytest4Warning(
|
|
||||||
"getfuncargvalue is deprecated, use getfixturevalue"
|
|
||||||
)
|
|
||||||
|
|
||||||
FUNCARGNAMES = PytestDeprecationWarning(
|
FUNCARGNAMES = PytestDeprecationWarning(
|
||||||
"The `funcargnames` attribute was an alias for `fixturenames`, "
|
"The `funcargnames` attribute was an alias for `fixturenames`, "
|
||||||
|
|
|
@ -470,13 +470,6 @@ class FixtureRequest(FuncargnamesCompatAttr):
|
||||||
"""
|
"""
|
||||||
return self._get_active_fixturedef(argname).cached_result[0]
|
return self._get_active_fixturedef(argname).cached_result[0]
|
||||||
|
|
||||||
def getfuncargvalue(self, argname):
|
|
||||||
""" Deprecated, use getfixturevalue. """
|
|
||||||
from _pytest import deprecated
|
|
||||||
|
|
||||||
warnings.warn(deprecated.GETFUNCARGVALUE, stacklevel=2)
|
|
||||||
return self.getfixturevalue(argname)
|
|
||||||
|
|
||||||
def _get_active_fixturedef(self, argname):
|
def _get_active_fixturedef(self, argname):
|
||||||
try:
|
try:
|
||||||
return self._fixture_defs[argname]
|
return self._fixture_defs[argname]
|
||||||
|
|
|
@ -32,10 +32,6 @@ def test_pytest_custom_cfg_unsupported(testdir):
|
||||||
testdir.runpytest("-c", "custom.cfg")
|
testdir.runpytest("-c", "custom.cfg")
|
||||||
|
|
||||||
|
|
||||||
def test_getfuncargvalue_is_deprecated(request):
|
|
||||||
pytest.deprecated_call(request.getfuncargvalue, "tmpdir")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.filterwarnings("default")
|
@pytest.mark.filterwarnings("default")
|
||||||
def test_resultlog_is_deprecated(testdir):
|
def test_resultlog_is_deprecated(testdir):
|
||||||
result = testdir.runpytest("--help")
|
result = testdir.runpytest("--help")
|
||||||
|
|
|
@ -599,8 +599,7 @@ class TestRequestBasic:
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines(["* 2 passed in *"])
|
result.stdout.fnmatch_lines(["* 2 passed in *"])
|
||||||
|
|
||||||
@pytest.mark.parametrize("getfixmethod", ("getfixturevalue", "getfuncargvalue"))
|
def test_getfixturevalue(self, testdir):
|
||||||
def test_getfixturevalue(self, testdir, getfixmethod):
|
|
||||||
item = testdir.getitem(
|
item = testdir.getitem(
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -613,30 +612,17 @@ class TestRequestBasic:
|
||||||
def test_func(something): pass
|
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
|
req = item._request
|
||||||
with warning_expectation:
|
|
||||||
fixture_fetcher = getattr(req, getfixmethod)
|
|
||||||
with pytest.raises(FixtureLookupError):
|
with pytest.raises(FixtureLookupError):
|
||||||
fixture_fetcher("notexists")
|
req.getfixturevalue("notexists")
|
||||||
val = fixture_fetcher("something")
|
val = req.getfixturevalue("something")
|
||||||
assert val == 1
|
assert val == 1
|
||||||
val = fixture_fetcher("something")
|
val = req.getfixturevalue("something")
|
||||||
assert val == 1
|
assert val == 1
|
||||||
val2 = fixture_fetcher("other")
|
val2 = req.getfixturevalue("other")
|
||||||
assert val2 == 2
|
assert val2 == 2
|
||||||
val2 = fixture_fetcher("other") # see about caching
|
val2 = req.getfixturevalue("other") # see about caching
|
||||||
assert val2 == 2
|
assert val2 == 2
|
||||||
pytest._fillfuncargs(item)
|
pytest._fillfuncargs(item)
|
||||||
assert item.funcargs["something"] == 1
|
assert item.funcargs["something"] == 1
|
||||||
|
|
Loading…
Reference in New Issue