Skip to content

Commit

Permalink
Remove Metafunc.addcall
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Dec 1, 2018
1 parent 090f7ff commit 40b85d7
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 233 deletions.
3 changes: 3 additions & 0 deletions changelog/3083.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove ``Metafunc.addcall``. This was the predecessor mechanism to ``@pytest.mark.parametrize``.

See our `docs <https://docs.pytest.org/en/latest/deprecations.html#metafunc-addcall>`__ on information on how to update your code.
31 changes: 24 additions & 7 deletions doc/en/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@ Defining ``pytest_plugins`` is now deprecated in non-top-level conftest.py
files because they will activate referenced plugins *globally*, which is surprising because for all other pytest
features ``conftest.py`` files are only *active* for tests at or below it.

Metafunc.addcall
~~~~~~~~~~~~~~~~

.. deprecated:: 3.3

:meth:`_pytest.python.Metafunc.addcall` was a precursor to the current parametrized mechanism. Users should use
:meth:`_pytest.python.Metafunc.parametrize` instead.

marks in ``pytest.mark.parametrize``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -274,6 +267,30 @@ Removed Features
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
an appropriate period of deprecation has passed.

Metafunc.addcall
~~~~~~~~~~~~~~~~

*Removed in version 4.0.*

:meth:`_pytest.python.Metafunc.addcall` was a precursor to the current parametrized mechanism. Users should use
:meth:`_pytest.python.Metafunc.parametrize` instead.

Example:

.. code-block:: python
def pytest_generate_tests(metafunc):
metafunc.addcall({"i": 1}, id="1")
metafunc.addcall({"i": 2}, id="2")
Becomes:

.. code-block:: python
def pytest_generate_tests(metafunc):
metafunc.parametrize("i", [1, 2], ids=["1", "2"])
``cached_setup``
~~~~~~~~~~~~~~~~

Expand Down
5 changes: 0 additions & 5 deletions src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@
"pycollector makeitem was removed as it is an accidentially leaked internal api"
)

METAFUNC_ADD_CALL = RemovedInPytest4Warning(
"Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.\n"
"Please use Metafunc.parametrize instead."
)

PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = RemovedInPytest4Warning(
"Defining pytest_plugins in a non-top-level conftest is deprecated, "
"because it affects the entire directory tree in a non-explicit way.\n"
Expand Down
3 changes: 1 addition & 2 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,7 @@ def _compute_fixture_value(self, fixturedef):
)
fail(msg, pytrace=False)
else:
# indices might not be set if old-style metafunc.addcall() was used
param_index = funcitem.callspec.indices.get(argname, 0)
param_index = funcitem.callspec.indices[argname]
# if a parametrize invocation set a scope it will override
# the static scope defined with the fixture function
paramscopenum = funcitem.callspec._arg2scopenum.get(argname)
Expand Down
42 changes: 0 additions & 42 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,48 +1022,6 @@ def _validate_if_using_arg_names(self, argnames, indirect):
pytrace=False,
)

def addcall(self, funcargs=None, id=NOTSET, param=NOTSET):
""" Add a new call to the underlying test function during the collection phase of a test run.
.. deprecated:: 3.3
Use :meth:`parametrize` instead.
Note that request.addcall() is called during the test collection phase prior and
independently to actual test execution. You should only use addcall()
if you need to specify multiple arguments of a test function.
:arg funcargs: argument keyword dictionary used when invoking
the test function.
:arg id: used for reporting and identification purposes. If you
don't supply an `id` an automatic unique id will be generated.
:arg param: a parameter which will be exposed to a later fixture function
invocation through the ``request.param`` attribute.
"""
warnings.warn(deprecated.METAFUNC_ADD_CALL, stacklevel=2)

assert funcargs is None or isinstance(funcargs, dict)
if funcargs is not None:
for name in funcargs:
if name not in self.fixturenames:
fail("funcarg %r not used in this function." % name)
else:
funcargs = {}
if id is None:
raise ValueError("id=None not allowed")
if id is NOTSET:
id = len(self._calls)
id = str(id)
if id in self._ids:
raise ValueError("duplicate id %r" % id)
self._ids.add(id)

cs = CallSpec2(self)
cs.setall(funcargs, id, param)
self._calls.append(cs)


def _find_parametrized_scope(argnames, arg2fixturedefs, indirect):
"""Find the most appropriate scope for a parametrized call based on its arguments.
Expand Down
5 changes: 2 additions & 3 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def test_skip_on_generated_funcarg_id(self, testdir):
"""
import pytest
def pytest_generate_tests(metafunc):
metafunc.addcall({'x': 3}, id='hello-123')
metafunc.parametrize('x', [3], ids=['hello-123'])
def pytest_runtest_setup(item):
print(item.keywords)
if 'hello-123' in item.keywords:
Expand All @@ -316,8 +316,7 @@ def test_direct_addressing_selects(self, testdir):
p = testdir.makepyfile(
"""
def pytest_generate_tests(metafunc):
metafunc.addcall({'i': 1}, id="1")
metafunc.addcall({'i': 2}, id="2")
metafunc.parametrize('i', [1, 2], ids=["1", "2"])
def test_func(i):
pass
"""
Expand Down
17 changes: 0 additions & 17 deletions testing/deprecated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,6 @@ def test():
)


def test_metafunc_addcall_deprecated(testdir):
testdir.makepyfile(
"""
def pytest_generate_tests(metafunc):
metafunc.addcall({'i': 1})
metafunc.addcall({'i': 2})
def test_func(i):
pass
"""
)
res = testdir.runpytest("-s", SHOW_PYTEST_WARNINGS_ARG)
assert res.ret == 0
res.stdout.fnmatch_lines(
["*Metafunc.addcall is deprecated*", "*2 passed, 2 warnings*"]
)


def test_terminal_reporter_writer_attr(pytestconfig):
"""Check that TerminalReporter._tw is also available as 'writer' (#2984)
This attribute is planned to be deprecated in 3.4.
Expand Down
Loading

0 comments on commit 40b85d7

Please sign in to comment.