Merge pull request #2932 from nicoddemus/deprecate-add-call
Deprecate metafunc.addcall
This commit is contained in:
		
						commit
						99a4a93dbc
					
				| 
						 | 
					@ -45,3 +45,8 @@ COLLECTOR_MAKEITEM = RemovedInPytest4Warning(
 | 
				
			||||||
    "pycollector makeitem was removed "
 | 
					    "pycollector makeitem was removed "
 | 
				
			||||||
    "as it is an accidentially leaked internal api"
 | 
					    "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."
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -837,9 +837,13 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
 | 
				
			||||||
        self._calls = newcalls
 | 
					        self._calls = newcalls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def addcall(self, funcargs=None, id=NOTSET, param=NOTSET):
 | 
					    def addcall(self, funcargs=None, id=NOTSET, param=NOTSET):
 | 
				
			||||||
        """ (deprecated, use parametrize) Add a new call to the underlying
 | 
					        """ Add a new call to the underlying test function during the collection phase of a test run.
 | 
				
			||||||
        test function during the collection phase of a test run.  Note that
 | 
					
 | 
				
			||||||
        request.addcall() is called during the test collection phase prior and
 | 
					        .. 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()
 | 
					        independently to actual test execution.  You should only use addcall()
 | 
				
			||||||
        if you need to specify multiple arguments of a test function.
 | 
					        if you need to specify multiple arguments of a test function.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -852,6 +856,8 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
 | 
				
			||||||
        :arg param: a parameter which will be exposed to a later fixture function
 | 
					        :arg param: a parameter which will be exposed to a later fixture function
 | 
				
			||||||
            invocation through the ``request.param`` attribute.
 | 
					            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)
 | 
					        assert funcargs is None or isinstance(funcargs, dict)
 | 
				
			||||||
        if funcargs is not None:
 | 
					        if funcargs is not None:
 | 
				
			||||||
            for name in funcargs:
 | 
					            for name in funcargs:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					Calls to ``Metafunc.addcall`` now emit a deprecation warning. This function is scheduled to be removed in ``pytest-4.0``.
 | 
				
			||||||
| 
						 | 
					@ -82,3 +82,20 @@ def test_resultlog_is_deprecated(testdir):
 | 
				
			||||||
        '*--result-log is deprecated and scheduled for removal in pytest 4.0*',
 | 
					        '*--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*',
 | 
					        '*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*",
 | 
				
			||||||
 | 
					    ])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue