Skip to content

Commit 40b85d7

Browse files
committed
Remove Metafunc.addcall
Fix #3083
1 parent 090f7ff commit 40b85d7

File tree

8 files changed

+37
-233
lines changed

8 files changed

+37
-233
lines changed

changelog/3083.removal.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove ``Metafunc.addcall``. This was the predecessor mechanism to ``@pytest.mark.parametrize``.
2+
3+
See our `docs <https://docs.pytest.org/en/latest/deprecations.html#metafunc-addcall>`__ on information on how to update your code.

doc/en/deprecations.rst

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@ Defining ``pytest_plugins`` is now deprecated in non-top-level conftest.py
168168
files because they will activate referenced plugins *globally*, which is surprising because for all other pytest
169169
features ``conftest.py`` files are only *active* for tests at or below it.
170170

171-
Metafunc.addcall
172-
~~~~~~~~~~~~~~~~
173-
174-
.. deprecated:: 3.3
175-
176-
:meth:`_pytest.python.Metafunc.addcall` was a precursor to the current parametrized mechanism. Users should use
177-
:meth:`_pytest.python.Metafunc.parametrize` instead.
178171

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

270+
Metafunc.addcall
271+
~~~~~~~~~~~~~~~~
272+
273+
*Removed in version 4.0.*
274+
275+
:meth:`_pytest.python.Metafunc.addcall` was a precursor to the current parametrized mechanism. Users should use
276+
:meth:`_pytest.python.Metafunc.parametrize` instead.
277+
278+
Example:
279+
280+
.. code-block:: python
281+
282+
def pytest_generate_tests(metafunc):
283+
metafunc.addcall({"i": 1}, id="1")
284+
metafunc.addcall({"i": 2}, id="2")
285+
286+
Becomes:
287+
288+
.. code-block:: python
289+
290+
def pytest_generate_tests(metafunc):
291+
metafunc.parametrize("i", [1, 2], ids=["1", "2"])
292+
293+
277294
``cached_setup``
278295
~~~~~~~~~~~~~~~~
279296

src/_pytest/deprecated.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@
9191
"pycollector makeitem was removed as it is an accidentially leaked internal api"
9292
)
9393

94-
METAFUNC_ADD_CALL = RemovedInPytest4Warning(
95-
"Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.\n"
96-
"Please use Metafunc.parametrize instead."
97-
)
98-
9994
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = RemovedInPytest4Warning(
10095
"Defining pytest_plugins in a non-top-level conftest is deprecated, "
10196
"because it affects the entire directory tree in a non-explicit way.\n"

src/_pytest/fixtures.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ def _compute_fixture_value(self, fixturedef):
568568
)
569569
fail(msg, pytrace=False)
570570
else:
571-
# indices might not be set if old-style metafunc.addcall() was used
572-
param_index = funcitem.callspec.indices.get(argname, 0)
571+
param_index = funcitem.callspec.indices[argname]
573572
# if a parametrize invocation set a scope it will override
574573
# the static scope defined with the fixture function
575574
paramscopenum = funcitem.callspec._arg2scopenum.get(argname)

src/_pytest/python.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,48 +1022,6 @@ def _validate_if_using_arg_names(self, argnames, indirect):
10221022
pytrace=False,
10231023
)
10241024

1025-
def addcall(self, funcargs=None, id=NOTSET, param=NOTSET):
1026-
""" Add a new call to the underlying test function during the collection phase of a test run.
1027-
1028-
.. deprecated:: 3.3
1029-
1030-
Use :meth:`parametrize` instead.
1031-
1032-
Note that request.addcall() is called during the test collection phase prior and
1033-
independently to actual test execution. You should only use addcall()
1034-
if you need to specify multiple arguments of a test function.
1035-
1036-
:arg funcargs: argument keyword dictionary used when invoking
1037-
the test function.
1038-
1039-
:arg id: used for reporting and identification purposes. If you
1040-
don't supply an `id` an automatic unique id will be generated.
1041-
1042-
:arg param: a parameter which will be exposed to a later fixture function
1043-
invocation through the ``request.param`` attribute.
1044-
"""
1045-
warnings.warn(deprecated.METAFUNC_ADD_CALL, stacklevel=2)
1046-
1047-
assert funcargs is None or isinstance(funcargs, dict)
1048-
if funcargs is not None:
1049-
for name in funcargs:
1050-
if name not in self.fixturenames:
1051-
fail("funcarg %r not used in this function." % name)
1052-
else:
1053-
funcargs = {}
1054-
if id is None:
1055-
raise ValueError("id=None not allowed")
1056-
if id is NOTSET:
1057-
id = len(self._calls)
1058-
id = str(id)
1059-
if id in self._ids:
1060-
raise ValueError("duplicate id %r" % id)
1061-
self._ids.add(id)
1062-
1063-
cs = CallSpec2(self)
1064-
cs.setall(funcargs, id, param)
1065-
self._calls.append(cs)
1066-
10671025

10681026
def _find_parametrized_scope(argnames, arg2fixturedefs, indirect):
10691027
"""Find the most appropriate scope for a parametrized call based on its arguments.

testing/acceptance_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def test_skip_on_generated_funcarg_id(self, testdir):
299299
"""
300300
import pytest
301301
def pytest_generate_tests(metafunc):
302-
metafunc.addcall({'x': 3}, id='hello-123')
302+
metafunc.parametrize('x', [3], ids=['hello-123'])
303303
def pytest_runtest_setup(item):
304304
print(item.keywords)
305305
if 'hello-123' in item.keywords:
@@ -316,8 +316,7 @@ def test_direct_addressing_selects(self, testdir):
316316
p = testdir.makepyfile(
317317
"""
318318
def pytest_generate_tests(metafunc):
319-
metafunc.addcall({'i': 1}, id="1")
320-
metafunc.addcall({'i': 2}, id="2")
319+
metafunc.parametrize('i', [1, 2], ids=["1", "2"])
321320
def test_func(i):
322321
pass
323322
"""

testing/deprecated_test.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,6 @@ def test():
105105
)
106106

107107

108-
def test_metafunc_addcall_deprecated(testdir):
109-
testdir.makepyfile(
110-
"""
111-
def pytest_generate_tests(metafunc):
112-
metafunc.addcall({'i': 1})
113-
metafunc.addcall({'i': 2})
114-
def test_func(i):
115-
pass
116-
"""
117-
)
118-
res = testdir.runpytest("-s", SHOW_PYTEST_WARNINGS_ARG)
119-
assert res.ret == 0
120-
res.stdout.fnmatch_lines(
121-
["*Metafunc.addcall is deprecated*", "*2 passed, 2 warnings*"]
122-
)
123-
124-
125108
def test_terminal_reporter_writer_attr(pytestconfig):
126109
"""Check that TerminalReporter._tw is also available as 'writer' (#2984)
127110
This attribute is planned to be deprecated in 3.4.

0 commit comments

Comments
 (0)