Skip to content

Commit 790806e

Browse files
authored
Merge pull request #5494 from Zac-HD/funcargnames-to-fixturenames
Deprecate funcargnames alias for fixturenames
2 parents 6a2d844 + ed85c83 commit 790806e

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
@@ -325,4 +325,8 @@ class FuncargnamesCompatAttr:
325325
@property
326326
def funcargnames(self):
327327
""" alias attribute for ``fixturenames`` for pre-2.3 compatibility"""
328+
import warnings
329+
from _pytest.deprecated import FUNCARGNAMES
330+
331+
warnings.warn(FUNCARGNAMES, stacklevel=2)
328332
return self.fixturenames

src/_pytest/deprecated.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
"getfuncargvalue is deprecated, use getfixturevalue"
4141
)
4242

43+
FUNCARGNAMES = PytestDeprecationWarning(
44+
"The `funcargnames` attribute was an alias for `fixturenames`, "
45+
"since pytest 2.3 - use the newer attribute instead."
46+
)
47+
4348
RAISES_MESSAGE_PARAMETER = PytestDeprecationWarning(
4449
"The 'message' parameter is deprecated.\n"
4550
"(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
@@ -654,7 +654,7 @@ def _schedule_finalizers(self, fixturedef, subrequest):
654654
# if the executing fixturedef was not explicitly requested in the argument list (via
655655
# getfixturevalue inside the fixture call) then ensure this fixture def will be finished
656656
# first
657-
if fixturedef.argname not in self.funcargnames:
657+
if fixturedef.argname not in self.fixturenames:
658658
fixturedef.addfinalizer(
659659
functools.partial(self._fixturedef.finish, request=self)
660660
)

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)