Skip to content

Commit ad4125d

Browse files
committed
Deprecate "pytest_funcarg__" prefix to declare fixtures
Fixes pytest-dev#1684
1 parent 5506dc7 commit ad4125d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

CHANGELOG.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@
188188
* ``yield``-based tests are considered deprecated and will be removed in pytest-4.0.
189189
Thanks `@nicoddemus`_ for the PR.
190190

191-
*
191+
* Using ``pytest_funcarg__`` prefix to declare fixtures is considered deprecated and will be
192+
removed in pytest-4.0 (`#1684`_).
193+
Thanks `@nicoddemus`_ for the PR.
192194

193195
*
194196

@@ -262,6 +264,7 @@
262264
.. _#1632: https://github.com/pytest-dev/pytest/issues/1632
263265
.. _#1633: https://github.com/pytest-dev/pytest/pull/1633
264266
.. _#1664: https://github.com/pytest-dev/pytest/pull/1664
267+
.. _#1684: https://github.com/pytest-dev/pytest/pull/1684
265268

266269
.. _@DRMacIver: https://github.com/DRMacIver
267270
.. _@RedBeardCode: https://github.com/RedBeardCode

_pytest/fixtures.py

+5
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,10 @@ def yield_fixture(scope="function", params=None, autouse=False, ids=None, name=N
865865
return FixtureFunctionMarker(scope, params, autouse, ids=ids, name=name)
866866

867867
defaultfuncargprefixmarker = fixture()
868+
funcarg_prefix_warning = 'declaring fixtures using "pytest_funcarg__" prefix is deprecated ' \
869+
'and scheduled to be removed in pytest 4.0.\n' \
870+
'remove the prefix and use the @pytest.fixture decorator instead'
871+
868872

869873

870874
@fixture(scope="session")
@@ -1043,6 +1047,7 @@ def parsefactories(self, node_or_obj, nodeid=NOTSET, unittest=False):
10431047
continue
10441048
marker = defaultfuncargprefixmarker
10451049
name = name[len(self._argprefix):]
1050+
self.config.warn('C1', funcarg_prefix_warning)
10461051
elif not isinstance(marker, FixtureFunctionMarker):
10471052
# magic globals with __getattr__ might have got us a wrong
10481053
# fixture attribute

testing/acceptance_test.py

+16
Original file line numberDiff line numberDiff line change
@@ -777,3 +777,19 @@ def test_gen():
777777
'*yield tests are deprecated, and scheduled to be removed in pytest 4.0*',
778778
'*2 passed*',
779779
])
780+
781+
782+
def test_funcarg_prefix_deprecation(testdir):
783+
testdir.makepyfile("""
784+
def pytest_funcarg__value():
785+
return 10
786+
787+
def test_funcarg_prefix(value):
788+
assert value == 10
789+
""")
790+
result = testdir.runpytest('-ra')
791+
result.stdout.fnmatch_lines([
792+
'*declaring fixtures using "pytest_funcarg__" prefix is deprecated and scheduled to be removed in pytest 4.0*',
793+
'*remove the prefix and use the @pytest.fixture decorator instead*',
794+
'*1 passed*',
795+
])

0 commit comments

Comments
 (0)