Skip to content

Commit 4c00ae3

Browse files
committed
Deprecate metafunc.addcall
Fix #2876
1 parent 1aeb58b commit 4c00ae3

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

_pytest/deprecated.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ class RemovedInPytest4Warning(DeprecationWarning):
4545
"pycollector makeitem was removed "
4646
"as it is an accidentially leaked internal api"
4747
)
48+
49+
METAFUNC_ADD_CALL = (
50+
"Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.\n"
51+
"Please use Metafunc.parametrize instead."
52+
)

_pytest/python.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,13 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
837837
self._calls = newcalls
838838

839839
def addcall(self, funcargs=None, id=NOTSET, param=NOTSET):
840-
""" (deprecated, use parametrize) Add a new call to the underlying
841-
test function during the collection phase of a test run. Note that
842-
request.addcall() is called during the test collection phase prior and
840+
""" Add a new call to the underlying test function during the collection phase of a test run.
841+
842+
.. deprecated:: 3.3
843+
844+
Use :meth:`parametrize` instead.
845+
846+
Note that request.addcall() is called during the test collection phase prior and
843847
independently to actual test execution. You should only use addcall()
844848
if you need to specify multiple arguments of a test function.
845849
@@ -852,6 +856,7 @@ def addcall(self, funcargs=None, id=NOTSET, param=NOTSET):
852856
:arg param: a parameter which will be exposed to a later fixture function
853857
invocation through the ``request.param`` attribute.
854858
"""
859+
self.config.warn('C1', message=deprecated.METAFUNC_ADD_CALL, fslocation=None)
855860
assert funcargs is None or isinstance(funcargs, dict)
856861
if funcargs is not None:
857862
for name in funcargs:

testing/deprecated_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,20 @@ def test():
8282
'*--result-log is deprecated and scheduled for removal in pytest 4.0*',
8383
'*See https://docs.pytest.org/*/usage.html#creating-resultlog-format-files for more information*',
8484
])
85+
86+
87+
@pytest.mark.filterwarnings('always:Metafunc.addcall is deprecated')
88+
def test_metafunc_addcall_deprecated(testdir):
89+
testdir.makepyfile("""
90+
def pytest_generate_tests(metafunc):
91+
metafunc.addcall({'i': 1})
92+
metafunc.addcall({'i': 2})
93+
def test_func(i):
94+
pass
95+
""")
96+
res = testdir.runpytest('-s')
97+
assert res.ret == 0
98+
res.stdout.fnmatch_lines([
99+
"*Metafunc.addcall is deprecated*",
100+
"*2 passed, 2 warnings*",
101+
])

0 commit comments

Comments
 (0)