Merge pull request #5494 from Zac-HD/funcargnames-to-fixturenames
Deprecate funcargnames alias for fixturenames
This commit is contained in:
commit
790806e865
|
@ -0,0 +1,2 @@
|
||||||
|
The ``funcargnames`` attribute has been an alias for ``fixturenames`` since
|
||||||
|
pytest 2.3, and is now deprecated in code too.
|
|
@ -19,6 +19,21 @@ Below is a complete list of all pytest features which are considered deprecated.
|
||||||
:class:`_pytest.warning_types.PytestWarning` or subclasses, which can be filtered using
|
:class:`_pytest.warning_types.PytestWarning` or subclasses, which can be filtered using
|
||||||
:ref:`standard warning filters <warnings>`.
|
:ref:`standard warning filters <warnings>`.
|
||||||
|
|
||||||
|
|
||||||
|
Removal of ``funcargnames`` alias for ``fixturenames``
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. deprecated:: 5.0
|
||||||
|
|
||||||
|
The ``FixtureRequest``, ``Metafunc``, and ``Function`` classes track the names of
|
||||||
|
their associated fixtures, with the aptly-named ``fixturenames`` attribute.
|
||||||
|
|
||||||
|
Prior to pytest 2.3, this attribute was named ``funcargnames``, and we have kept
|
||||||
|
that as an alias since. It is finally due for removal, as it is often confusing
|
||||||
|
in places where we or plugin authors must distinguish between fixture names and
|
||||||
|
names supplied by non-fixture things such as ``pytest.mark.parametrize``.
|
||||||
|
|
||||||
|
|
||||||
.. _`raises message deprecated`:
|
.. _`raises message deprecated`:
|
||||||
|
|
||||||
``"message"`` parameter of ``pytest.raises``
|
``"message"`` parameter of ``pytest.raises``
|
||||||
|
|
|
@ -325,4 +325,8 @@ class FuncargnamesCompatAttr:
|
||||||
@property
|
@property
|
||||||
def funcargnames(self):
|
def funcargnames(self):
|
||||||
""" alias attribute for ``fixturenames`` for pre-2.3 compatibility"""
|
""" alias attribute for ``fixturenames`` for pre-2.3 compatibility"""
|
||||||
|
import warnings
|
||||||
|
from _pytest.deprecated import FUNCARGNAMES
|
||||||
|
|
||||||
|
warnings.warn(FUNCARGNAMES, stacklevel=2)
|
||||||
return self.fixturenames
|
return self.fixturenames
|
||||||
|
|
|
@ -40,6 +40,11 @@ GETFUNCARGVALUE = RemovedInPytest4Warning(
|
||||||
"getfuncargvalue is deprecated, use getfixturevalue"
|
"getfuncargvalue is deprecated, use getfixturevalue"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
FUNCARGNAMES = PytestDeprecationWarning(
|
||||||
|
"The `funcargnames` attribute was an alias for `fixturenames`, "
|
||||||
|
"since pytest 2.3 - use the newer attribute instead."
|
||||||
|
)
|
||||||
|
|
||||||
RAISES_MESSAGE_PARAMETER = PytestDeprecationWarning(
|
RAISES_MESSAGE_PARAMETER = PytestDeprecationWarning(
|
||||||
"The 'message' parameter is deprecated.\n"
|
"The 'message' parameter is deprecated.\n"
|
||||||
"(did you mean to use `match='some regex'` to check the exception message?)\n"
|
"(did you mean to use `match='some regex'` to check the exception message?)\n"
|
||||||
|
|
|
@ -654,7 +654,7 @@ class SubRequest(FixtureRequest):
|
||||||
# if the executing fixturedef was not explicitly requested in the argument list (via
|
# if the executing fixturedef was not explicitly requested in the argument list (via
|
||||||
# getfixturevalue inside the fixture call) then ensure this fixture def will be finished
|
# getfixturevalue inside the fixture call) then ensure this fixture def will be finished
|
||||||
# first
|
# first
|
||||||
if fixturedef.argname not in self.funcargnames:
|
if fixturedef.argname not in self.fixturenames:
|
||||||
fixturedef.addfinalizer(
|
fixturedef.addfinalizer(
|
||||||
functools.partial(self._fixturedef.finish, request=self)
|
functools.partial(self._fixturedef.finish, request=self)
|
||||||
)
|
)
|
||||||
|
|
|
@ -793,11 +793,14 @@ class TestRequestBasic:
|
||||||
"""
|
"""
|
||||||
import pytest
|
import pytest
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
|
with pytest.warns(pytest.PytestDeprecationWarning):
|
||||||
assert metafunc.funcargnames == metafunc.fixturenames
|
assert metafunc.funcargnames == metafunc.fixturenames
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fn(request):
|
def fn(request):
|
||||||
|
with pytest.warns(pytest.PytestDeprecationWarning):
|
||||||
assert request._pyfuncitem.funcargnames == \
|
assert request._pyfuncitem.funcargnames == \
|
||||||
request._pyfuncitem.fixturenames
|
request._pyfuncitem.fixturenames
|
||||||
|
with pytest.warns(pytest.PytestDeprecationWarning):
|
||||||
return request.funcargnames, request.fixturenames
|
return request.funcargnames, request.fixturenames
|
||||||
|
|
||||||
def test_hello(fn):
|
def test_hello(fn):
|
||||||
|
|
|
@ -1205,7 +1205,7 @@ class TestMetafuncFunctional:
|
||||||
import pytest
|
import pytest
|
||||||
values = []
|
values = []
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
if "arg" in metafunc.funcargnames:
|
if "arg" in metafunc.fixturenames:
|
||||||
metafunc.parametrize("arg", [1,2], indirect=True,
|
metafunc.parametrize("arg", [1,2], indirect=True,
|
||||||
scope=%r)
|
scope=%r)
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
Loading…
Reference in New Issue