Skip to content

Commit

Permalink
Deprecate "pytest_funcarg__" prefix to declare fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Jul 12, 2016
1 parent 5506dc7 commit ad4125d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@
* ``yield``-based tests are considered deprecated and will be removed in pytest-4.0.
Thanks `@nicoddemus`_ for the PR.

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

*

Expand Down Expand Up @@ -262,6 +264,7 @@
.. _#1632: https://github.com/pytest-dev/pytest/issues/1632
.. _#1633: https://github.com/pytest-dev/pytest/pull/1633
.. _#1664: https://github.com/pytest-dev/pytest/pull/1664
.. _#1684: https://github.com/pytest-dev/pytest/pull/1684

.. _@DRMacIver: https://github.com/DRMacIver
.. _@RedBeardCode: https://github.com/RedBeardCode
Expand Down
5 changes: 5 additions & 0 deletions _pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@ def yield_fixture(scope="function", params=None, autouse=False, ids=None, name=N
return FixtureFunctionMarker(scope, params, autouse, ids=ids, name=name)

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



@fixture(scope="session")
Expand Down Expand Up @@ -1043,6 +1047,7 @@ def parsefactories(self, node_or_obj, nodeid=NOTSET, unittest=False):
continue
marker = defaultfuncargprefixmarker
name = name[len(self._argprefix):]
self.config.warn('C1', funcarg_prefix_warning)
elif not isinstance(marker, FixtureFunctionMarker):
# magic globals with __getattr__ might have got us a wrong
# fixture attribute
Expand Down
16 changes: 16 additions & 0 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,19 @@ def test_gen():
'*yield tests are deprecated, and scheduled to be removed in pytest 4.0*',
'*2 passed*',
])


def test_funcarg_prefix_deprecation(testdir):
testdir.makepyfile("""
def pytest_funcarg__value():
return 10
def test_funcarg_prefix(value):
assert value == 10
""")
result = testdir.runpytest('-ra')
result.stdout.fnmatch_lines([
'*declaring fixtures using "pytest_funcarg__" prefix is deprecated and scheduled to be removed in pytest 4.0*',
'*remove the prefix and use the @pytest.fixture decorator instead*',
'*1 passed*',
])

0 comments on commit ad4125d

Please sign in to comment.