* performing funcarg setup during setup-phase
* make item.runtest() be a clean function and have the caller deal with the deprecated invocation --HG-- branch : trunk
This commit is contained in:
parent
aad04ea8ae
commit
a72b351139
|
@ -247,7 +247,7 @@ class FunctionMixin(PyobjMixin):
|
|||
obj = self.parent.obj
|
||||
setup_func_or_method = getattr(obj, name, None)
|
||||
if setup_func_or_method is not None:
|
||||
return setup_func_or_method(self.obj)
|
||||
setup_func_or_method(self.obj)
|
||||
|
||||
def teardown(self):
|
||||
""" perform teardown for this test function. """
|
||||
|
@ -345,14 +345,18 @@ class Function(FunctionMixin, py.test.collect.Item):
|
|||
|
||||
def runtest(self):
|
||||
""" execute the given test function. """
|
||||
if not self._deprecated_testexecution():
|
||||
self.setupargs() # XXX move to setup() / consider funcargs plugin
|
||||
ret = self.config.api.pytest_pyfunc_call(
|
||||
pyfuncitem=self, args=self._args, kwargs=self.funcargs)
|
||||
self.config.api.pytest_pyfunc_call(pyfuncitem=self,
|
||||
args=self._args, kwargs=self.funcargs)
|
||||
|
||||
def setupargs(self):
|
||||
def setup(self):
|
||||
super(Function, self).setup()
|
||||
self._setupfuncargs()
|
||||
|
||||
def _setupfuncargs(self):
|
||||
if self._args:
|
||||
# generator case: we don't do anything then
|
||||
# functions yielded from a generator: we don't want
|
||||
# to support that because we want to go here anyway:
|
||||
# http://bitbucket.org/hpk42/py-trunk/issue/2/next-generation-generative-tests
|
||||
pass
|
||||
else:
|
||||
# standard Python Test function/method case
|
||||
|
|
|
@ -20,7 +20,8 @@ def basic_run_report(item, pdb=None):
|
|||
item.config._setupstate.prepare(item)
|
||||
try:
|
||||
when = "execute"
|
||||
res = item.runtest()
|
||||
if not item._deprecated_testexecution():
|
||||
item.runtest()
|
||||
finally:
|
||||
when = "teardown"
|
||||
item.config._setupstate.teardown_exact(item)
|
||||
|
|
|
@ -105,7 +105,7 @@ class TestCollectDeprecated:
|
|||
funcitem = modcol.collect()[0]
|
||||
assert funcitem.name == 'test_func'
|
||||
recwarn.clear()
|
||||
funcitem.runtest()
|
||||
funcitem._deprecated_testexecution()
|
||||
recwarn.pop(DeprecationWarning)
|
||||
|
||||
def test_function_custom_execute(self, testdir, recwarn):
|
||||
|
|
|
@ -8,7 +8,7 @@ class TestFuncargs:
|
|||
return 42
|
||||
""")
|
||||
item = testdir.getitem("def test_func(some): pass")
|
||||
exc = py.test.raises(LookupError, "item.setupargs()")
|
||||
exc = py.test.raises(LookupError, "item._setupfuncargs()")
|
||||
s = str(exc.value)
|
||||
assert s.find("xyzsomething") != -1
|
||||
|
||||
|
@ -18,7 +18,7 @@ class TestFuncargs:
|
|||
def pytest_funcarg__some(self, request):
|
||||
return request.function.__name__
|
||||
item.config.pluginmanager.register(Provider())
|
||||
item.setupargs()
|
||||
item._setupfuncargs()
|
||||
assert len(item.funcargs) == 1
|
||||
|
||||
def test_funcarg_lookup_default_gets_overriden(self, testdir):
|
||||
|
@ -27,7 +27,7 @@ class TestFuncargs:
|
|||
def pytest_funcarg__other(self, request):
|
||||
return request.function.__name__
|
||||
item.config.pluginmanager.register(Provider())
|
||||
item.setupargs()
|
||||
item._setupfuncargs()
|
||||
assert len(item.funcargs) == 1
|
||||
name, value = item.funcargs.popitem()
|
||||
assert name == "other"
|
||||
|
@ -41,7 +41,7 @@ class TestFuncargs:
|
|||
def pytest_funcarg__other(self, request):
|
||||
return 42
|
||||
item.config.pluginmanager.register(Provider())
|
||||
item.setupargs()
|
||||
item._setupfuncargs()
|
||||
assert len(item.funcargs) == 2
|
||||
assert item.funcargs['some'] == "test_func"
|
||||
assert item.funcargs['other'] == 42
|
||||
|
@ -58,9 +58,9 @@ class TestFuncargs:
|
|||
pass
|
||||
""")
|
||||
item1, item2 = testdir.genitems([modcol])
|
||||
item1.setupargs()
|
||||
item1._setupfuncargs()
|
||||
assert item1.funcargs['something'] == "test_method"
|
||||
item2.setupargs()
|
||||
item2._setupfuncargs()
|
||||
assert item2.funcargs['something'] == "test_func"
|
||||
|
||||
class TestRequest:
|
||||
|
|
Loading…
Reference in New Issue