Skip to content

Commit 99a4a93

Browse files
Merge pull request #2932 from nicoddemus/deprecate-add-call
Deprecate metafunc.addcall
2 parents c19708b + 99ba3c9 commit 99a4a93

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

_pytest/deprecated.py

+5
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

+9-3
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,8 @@ 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+
if self.config:
860+
self.config.warn('C1', message=deprecated.METAFUNC_ADD_CALL, fslocation=None)
855861
assert funcargs is None or isinstance(funcargs, dict)
856862
if funcargs is not None:
857863
for name in funcargs:

changelog/2876.trivial

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Calls to ``Metafunc.addcall`` now emit a deprecation warning. This function is scheduled to be removed in ``pytest-4.0``.

testing/deprecated_test.py

+17
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)