Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate yield tests funcarg prefix #1714

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Deprecate "pytest_funcarg__" prefix to declare fixtures
Fixes #1684
  • Loading branch information
nicoddemus committed Jul 12, 2016
commit ad4125dc0d0c941f50ae42aa61663a3895a6fd9f
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*',
])