Skip to content

Commit 138cdcf

Browse files
committed
Deprecate funcargnames alias
1 parent 4d5780f commit 138cdcf

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

changelog/466.deprecation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``funcargnames`` attribute has been an alias for ``fixturenames`` since
2+
pytest 2.3, and is now deprecated in code too.

doc/en/deprecations.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ Below is a complete list of all pytest features which are considered deprecated.
1919
:class:`_pytest.warning_types.PytestWarning` or subclasses, which can be filtered using
2020
:ref:`standard warning filters <warnings>`.
2121

22+
23+
Removal of ``funcargnames`` alias for ``fixturenames``
24+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+
26+
.. deprecated:: 5.0
27+
28+
The ``FixtureRequest``, ``Metafunc``, and ``Function`` classes track the names of
29+
their associated fixtures, with the aptly-named ``fixturenames`` attribute.
30+
31+
Prior to pytest 2.3, this attribute was named ``funcargnames``, and we have kept
32+
that as an alias since. It is finally due for removal, as it is often confusing
33+
in places where we or plugin authors must distinguish between fixture names and
34+
names supplied by non-fixture things such as ``pytest.mark.parametrize``.
35+
36+
2237
.. _`raises message deprecated`:
2338

2439
``"message"`` parameter of ``pytest.raises``

src/_pytest/compat.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,8 @@ class FuncargnamesCompatAttr:
324324
@property
325325
def funcargnames(self):
326326
""" alias attribute for ``fixturenames`` for pre-2.3 compatibility"""
327+
import warnings
328+
from _pytest.deprecated import FUNCARGNAMES
329+
330+
warnings.warn(FUNCARGNAMES, stacklevel=2)
327331
return self.fixturenames

src/_pytest/deprecated.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
"getfuncargvalue is deprecated, use getfixturevalue"
3333
)
3434

35+
FUNCARGNAMES = PytestDeprecationWarning(
36+
"The `funcargnames` attribute was an alias for `fixturenames`, "
37+
"since pytest 2.3 - use the newer attribute instead."
38+
)
39+
3540
RAISES_MESSAGE_PARAMETER = PytestDeprecationWarning(
3641
"The 'message' parameter is deprecated.\n"
3742
"(did you mean to use `match='some regex'` to check the exception message?)\n"

src/_pytest/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def _schedule_finalizers(self, fixturedef, subrequest):
660660
# if the executing fixturedef was not explicitly requested in the argument list (via
661661
# getfixturevalue inside the fixture call) then ensure this fixture def will be finished
662662
# first
663-
if fixturedef.argname not in self.funcargnames:
663+
if fixturedef.argname not in self.fixturenames:
664664
fixturedef.addfinalizer(
665665
functools.partial(self._fixturedef.finish, request=self)
666666
)

testing/python/fixtures.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,15 @@ def test_funcargnames_compatattr(self, testdir):
793793
"""
794794
import pytest
795795
def pytest_generate_tests(metafunc):
796-
assert metafunc.funcargnames == metafunc.fixturenames
796+
with pytest.warns(pytest.PytestDeprecationWarning):
797+
assert metafunc.funcargnames == metafunc.fixturenames
797798
@pytest.fixture
798799
def fn(request):
799-
assert request._pyfuncitem.funcargnames == \
800-
request._pyfuncitem.fixturenames
801-
return request.funcargnames, request.fixturenames
800+
with pytest.warns(pytest.PytestDeprecationWarning):
801+
assert request._pyfuncitem.funcargnames == \
802+
request._pyfuncitem.fixturenames
803+
with pytest.warns(pytest.PytestDeprecationWarning):
804+
return request.funcargnames, request.fixturenames
802805
803806
def test_hello(fn):
804807
assert fn[0] == fn[1]

testing/python/metafunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ def test_parametrize_scope_overrides(self, testdir, scope, length):
12051205
import pytest
12061206
values = []
12071207
def pytest_generate_tests(metafunc):
1208-
if "arg" in metafunc.funcargnames:
1208+
if "arg" in metafunc.fixturenames:
12091209
metafunc.parametrize("arg", [1,2], indirect=True,
12101210
scope=%r)
12111211
@pytest.fixture

0 commit comments

Comments
 (0)