back out pytest_configure_funcargs hook for now
This commit is contained in:
parent
332bceeb7a
commit
ce1b456762
|
@ -10,8 +10,7 @@ Changes between 2.0.3 and 2.1.0.DEV
|
||||||
- fix issue47: timing output in junitxml for test cases is now correct
|
- fix issue47: timing output in junitxml for test cases is now correct
|
||||||
- fix issue48: typo in MarkInfo repr leading to exception
|
- fix issue48: typo in MarkInfo repr leading to exception
|
||||||
- fix issue49: avoid confusing error when initizaliation partially fails
|
- fix issue49: avoid confusing error when initizaliation partially fails
|
||||||
- introduce XXX pytest_configure_funcargs hack (thanks Ronny)
|
- fix issue44: env/username expansion for junitxml file path
|
||||||
- env/username expansion for junitxml file path (fixes issue44)
|
|
||||||
|
|
||||||
Changes between 2.0.2 and 2.0.3
|
Changes between 2.0.2 and 2.0.3
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#
|
#
|
||||||
__version__ = '2.1.0.dev3'
|
__version__ = '2.1.0.dev4'
|
||||||
|
|
|
@ -115,9 +115,6 @@ pytest_pyfunc_call.firstresult = True
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
""" generate (multiple) parametrized calls to a test function."""
|
""" generate (multiple) parametrized calls to a test function."""
|
||||||
|
|
||||||
def pytest_configure_funcargs(request):
|
|
||||||
""" configure funcargs """
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
# generic runtest related hooks
|
# generic runtest related hooks
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
|
@ -505,16 +505,6 @@ def fillfuncargs(function):
|
||||||
request = FuncargRequest(pyfuncitem=function)
|
request = FuncargRequest(pyfuncitem=function)
|
||||||
request._fillfuncargs()
|
request._fillfuncargs()
|
||||||
|
|
||||||
def pytest_configure_funcargs(request):
|
|
||||||
argnames = getfuncargnames(request.function)
|
|
||||||
if argnames:
|
|
||||||
item = request._pyfuncitem
|
|
||||||
assert not getattr(item, '_args', None), (
|
|
||||||
"yielded functions cannot have funcargs")
|
|
||||||
for argname in argnames:
|
|
||||||
if argname not in item.funcargs:
|
|
||||||
item.funcargs[argname] = request.getfuncargvalue(argname)
|
|
||||||
|
|
||||||
_notexists = object()
|
_notexists = object()
|
||||||
class CallSpec:
|
class CallSpec:
|
||||||
def __init__(self, funcargs, id, param):
|
def __init__(self, funcargs, id, param):
|
||||||
|
@ -636,6 +626,14 @@ class FuncargRequest:
|
||||||
""" the file system path of the test module which collected this test. """
|
""" the file system path of the test module which collected this test. """
|
||||||
return self._pyfuncitem.fspath
|
return self._pyfuncitem.fspath
|
||||||
|
|
||||||
|
def _fillfuncargs(self):
|
||||||
|
argnames = getfuncargnames(self.function)
|
||||||
|
if argnames:
|
||||||
|
assert not getattr(self._pyfuncitem, '_args', None), (
|
||||||
|
"yielded functions cannot have funcargs")
|
||||||
|
for argname in argnames:
|
||||||
|
if argname not in self._pyfuncitem.funcargs:
|
||||||
|
self._pyfuncitem.funcargs[argname] = self.getfuncargvalue(argname)
|
||||||
|
|
||||||
|
|
||||||
def applymarker(self, marker):
|
def applymarker(self, marker):
|
||||||
|
@ -707,9 +705,6 @@ class FuncargRequest:
|
||||||
self._currentarg = oldarg
|
self._currentarg = oldarg
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _fillfuncargs(self):
|
|
||||||
self.config.hook.pytest_configure_funcargs.pcall(self._plugins, request=self)
|
|
||||||
|
|
||||||
def _getscopeitem(self, scope):
|
def _getscopeitem(self, scope):
|
||||||
if scope == "function":
|
if scope == "function":
|
||||||
return self._pyfuncitem
|
return self._pyfuncitem
|
||||||
|
|
|
@ -115,9 +115,6 @@ think of as "resources").
|
||||||
.. _`funcarg factory`:
|
.. _`funcarg factory`:
|
||||||
.. _factory:
|
.. _factory:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The funcarg **request** object
|
The funcarg **request** object
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
|
@ -143,16 +140,6 @@ factory and provides access to test configuration and context:
|
||||||
.. _`parametrizing-tests`:
|
.. _`parametrizing-tests`:
|
||||||
.. _`parametrized test functions`:
|
.. _`parametrized test functions`:
|
||||||
|
|
||||||
|
|
||||||
Reconfiguring funcargs in a test's setup
|
|
||||||
========================================
|
|
||||||
|
|
||||||
Sometimes there is need to do additional funcarg setup steps
|
|
||||||
which are outside of the normal setup and involve more than just one funcarg.
|
|
||||||
For that reason the ``pytest_configure_funcargs(request)`` hook
|
|
||||||
is called to implement and extend the funcarg filling mechanism.
|
|
||||||
|
|
||||||
|
|
||||||
Parametrizing multiple calls to a test function
|
Parametrizing multiple calls to a test function
|
||||||
===========================================================
|
===========================================================
|
||||||
|
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -22,7 +22,7 @@ def main():
|
||||||
name='pytest',
|
name='pytest',
|
||||||
description='py.test: simple powerful testing with Python',
|
description='py.test: simple powerful testing with Python',
|
||||||
long_description = long_description,
|
long_description = long_description,
|
||||||
version='2.1.0.dev3',
|
version='2.1.0.dev4',
|
||||||
url='http://pytest.org',
|
url='http://pytest.org',
|
||||||
license='MIT license',
|
license='MIT license',
|
||||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||||
|
@ -67,4 +67,4 @@ def make_entry_points():
|
||||||
return {'console_scripts': l}
|
return {'console_scripts': l}
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
|
@ -606,22 +606,6 @@ class TestFillFuncArgs:
|
||||||
fillfuncargs(item)
|
fillfuncargs(item)
|
||||||
assert len(item.funcargs) == 1
|
assert len(item.funcargs) == 1
|
||||||
|
|
||||||
def test_configure_hook(self, testdir):
|
|
||||||
item = testdir.getitem("def test_func(some, other=20): pass")
|
|
||||||
class Provider:
|
|
||||||
def pytest_funcarg__some(self, request):
|
|
||||||
return []
|
|
||||||
def pytest_configure_funcargs(self, request):
|
|
||||||
request.getfuncargvalue('some').append(1)
|
|
||||||
item.config.pluginmanager.register(Provider())
|
|
||||||
if hasattr(item, '_args'):
|
|
||||||
del item._args
|
|
||||||
from _pytest.python import fillfuncargs
|
|
||||||
fillfuncargs(item)
|
|
||||||
assert len(item.funcargs) == 1
|
|
||||||
assert item.funcargs['some'] == [1]
|
|
||||||
|
|
||||||
|
|
||||||
class TestRequest:
|
class TestRequest:
|
||||||
def test_request_attributes(self, testdir):
|
def test_request_attributes(self, testdir):
|
||||||
item = testdir.getitem("""
|
item = testdir.getitem("""
|
||||||
|
|
Loading…
Reference in New Issue