Skip to content

Commit

Permalink
Remove pytest_funcarg__ prefix support for defining fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Dec 13, 2018
1 parent 26d202a commit affe752
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 96 deletions.
4 changes: 4 additions & 0 deletions changelog/4543.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Remove support to define fixtures using the ``pytest_funcarg__`` prefix. Use the ``@pytest.fixture`` decorator instead.

See our `docs <https://docs.pytest.org/en/latest/deprecations.html#pytest-funcarg-prefix>`__ on information on how to update your code.

41 changes: 21 additions & 20 deletions doc/en/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,26 +237,6 @@ By passing a string, users expect that pytest will interpret that command-line u
on (for example ``bash`` or ``Powershell``), but this is very hard/impossible to do in a portable way.


``pytest_funcarg__`` prefix
~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 3.0

In very early pytest versions fixtures could be defined using the ``pytest_funcarg__`` prefix:

.. code-block:: python
def pytest_funcarg__data():
return SomeData()
Switch over to the ``@pytest.fixture`` decorator:

.. code-block:: python
@pytest.fixture
def data():
return SomeData()
[pytest] section in setup.cfg files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -295,6 +275,27 @@ collection.
This issue should affect only advanced plugins who create new collection types, so if you see this warning
message please contact the authors so they can change the code.

``pytest_funcarg__`` prefix
~~~~~~~~~~~~~~~~~~~~~~~~~~~

*Removed in version 4.0.*

In very early pytest versions fixtures could be defined using the ``pytest_funcarg__`` prefix:

.. code-block:: python
def pytest_funcarg__data():
return SomeData()
Switch over to the ``@pytest.fixture`` decorator:

.. code-block:: python
@pytest.fixture
def data():
return SomeData()
Metafunc.addcall
~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ def parse_hookimpl_opts(self, plugin, name):
# (see issue #1073)
if not name.startswith("pytest_"):
return
# ignore some historic special names which can not be hooks anyway
if name == "pytest_plugins" or name.startswith("pytest_funcarg__"):
# ignore names which can not be hooks
if name == "pytest_plugins":
return

method = getattr(plugin, name)
Expand Down
6 changes: 0 additions & 6 deletions src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@

YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored"

FUNCARG_PREFIX = UnformattedWarning(
RemovedInPytest4Warning,
'{name}: declaring fixtures using "pytest_funcarg__" prefix is deprecated '
"and scheduled to be removed in pytest 4.0. "
"Please remove the prefix and use the @pytest.fixture decorator instead.",
)

FIXTURE_FUNCTION_CALL = UnformattedWarning(
RemovedInPytest4Warning,
Expand Down
31 changes: 4 additions & 27 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
from _pytest.outcomes import fail
from _pytest.outcomes import TEST_OUTCOME

FIXTURE_MSG = 'fixtures cannot have "pytest_funcarg__" prefix and be decorated with @pytest.fixture:\n{}'


@attr.s(frozen=True)
class PseudoFixtureDef(object):
Expand Down Expand Up @@ -1117,7 +1115,6 @@ class FixtureManager(object):
by a lookup of their FuncFixtureInfo.
"""

_argprefix = "pytest_funcarg__"
FixtureLookupError = FixtureLookupError
FixtureLookupErrorRepr = FixtureLookupErrorRepr

Expand Down Expand Up @@ -1255,8 +1252,6 @@ def pytest_collection_modifyitems(self, items):
items[:] = reorder_items(items)

def parsefactories(self, node_or_obj, nodeid=NOTSET, unittest=False):
from _pytest import deprecated

if nodeid is not NOTSET:
holderobj = node_or_obj
else:
Expand All @@ -1272,31 +1267,13 @@ def parsefactories(self, node_or_obj, nodeid=NOTSET, unittest=False):
# access below can raise. safe_getatt() ignores such exceptions.
obj = safe_getattr(holderobj, name, None)
marker = getfixturemarker(obj)
# fixture functions have a pytest_funcarg__ prefix (pre-2.3 style)
# or are "@pytest.fixture" marked
if marker is None:
if not name.startswith(self._argprefix):
continue
if not callable(obj):
continue
marker = defaultfuncargprefixmarker

filename, lineno = getfslineno(obj)
warnings.warn_explicit(
deprecated.FUNCARG_PREFIX.format(name=name),
category=None,
filename=str(filename),
lineno=lineno + 1,
)
name = name[len(self._argprefix) :]
elif not isinstance(marker, FixtureFunctionMarker):
if not isinstance(marker, FixtureFunctionMarker):
# magic globals with __getattr__ might have got us a wrong
# fixture attribute
continue
else:
if marker.name:
name = marker.name
assert not name.startswith(self._argprefix), FIXTURE_MSG.format(name)

if marker.name:
name = marker.name

# during fixture definition we wrap the original fixture function
# to issue a warning if called directly, so here we unwrap it in order to not emit the warning
Expand Down
22 changes: 0 additions & 22 deletions testing/deprecated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@
pytestmark = pytest.mark.pytester_example_path("deprecated")


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", SHOW_PYTEST_WARNINGS_ARG)
result.stdout.fnmatch_lines(
[
(
"*test_funcarg_prefix_deprecation.py:1: *pytest_funcarg__value: "
'declaring fixtures using "pytest_funcarg__" prefix is deprecated*'
),
"*1 passed*",
]
)


@pytest.mark.filterwarnings("default")
def test_pytest_setup_cfg_deprecated(testdir):
testdir.makefile(
Expand Down
19 changes: 0 additions & 19 deletions testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,25 +627,6 @@ def test_func(something): pass
print(ss.stack)
assert teardownlist == [1]

def test_mark_as_fixture_with_prefix_and_decorator_fails(self, testdir):
testdir.makeconftest(
"""
import pytest
@pytest.fixture
def pytest_funcarg__marked_with_prefix_and_decorator():
pass
"""
)
result = testdir.runpytest_subprocess()
assert result.ret != 0
result.stdout.fnmatch_lines(
[
"*AssertionError: fixtures cannot have*@pytest.fixture*",
"*pytest_funcarg__marked_with_prefix_and_decorator*",
]
)

def test_request_addfinalizer_failing_setup(self, testdir):
testdir.makepyfile(
"""
Expand Down

0 comments on commit affe752

Please sign in to comment.