Skip to content

Deprecate metafunc.addcall #2932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions _pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ class RemovedInPytest4Warning(DeprecationWarning):
"pycollector makeitem was removed "
"as it is an accidentially leaked internal api"
)

METAFUNC_ADD_CALL = (
"Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.\n"
"Please use Metafunc.parametrize instead."
)
12 changes: 9 additions & 3 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,13 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
self._calls = newcalls

def addcall(self, funcargs=None, id=NOTSET, param=NOTSET):
""" (deprecated, use parametrize) Add a new call to the underlying
test function during the collection phase of a test run. Note that
request.addcall() is called during the test collection phase prior and
""" 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.

Expand All @@ -852,6 +856,8 @@ def addcall(self, funcargs=None, id=NOTSET, param=NOTSET):
:arg param: a parameter which will be exposed to a later fixture function
invocation through the ``request.param`` attribute.
"""
if self.config:
self.config.warn('C1', message=deprecated.METAFUNC_ADD_CALL, fslocation=None)
assert funcargs is None or isinstance(funcargs, dict)
if funcargs is not None:
for name in funcargs:
Expand Down
1 change: 1 addition & 0 deletions changelog/2876.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Calls to ``Metafunc.addcall`` now emit a deprecation warning. This function is scheduled to be removed in ``pytest-4.0``.
17 changes: 17 additions & 0 deletions testing/deprecated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,20 @@ def test():
'*--result-log is deprecated and scheduled for removal in pytest 4.0*',
'*See https://docs.pytest.org/*/usage.html#creating-resultlog-format-files for more information*',
])


@pytest.mark.filterwarnings('always:Metafunc.addcall is deprecated')
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')
assert res.ret == 0
res.stdout.fnmatch_lines([
"*Metafunc.addcall is deprecated*",
"*2 passed, 2 warnings*",
])