diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7213e772e..0d55d73fd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/_pytest/fixtures.py b/_pytest/fixtures.py index fcae06bdc..0260e14e2 100644 --- a/_pytest/fixtures.py +++ b/_pytest/fixtures.py @@ -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 diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index ff56da3b1..72cd18f11 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -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*', + ])