Deprecate "pytest_funcarg__" prefix to declare fixtures

Fixes #1684
This commit is contained in:
Bruno Oliveira 2016-07-11 21:12:50 -03:00
parent 5506dc700c
commit ad4125dc0d
3 changed files with 25 additions and 1 deletions

View File

@ -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.
*
@ -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

View File

@ -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")
@ -1043,6 +1047,7 @@ class FixtureManager:
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

View File

@ -777,3 +777,19 @@ def test_yield_tests_deprecation(testdir):
'*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*',
])