* 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:
holger krekel 2009-05-06 08:38:42 +02:00
parent aad04ea8ae
commit a72b351139
4 changed files with 20 additions and 15 deletions

View File

@ -247,7 +247,7 @@ class FunctionMixin(PyobjMixin):
obj = self.parent.obj obj = self.parent.obj
setup_func_or_method = getattr(obj, name, None) setup_func_or_method = getattr(obj, name, None)
if setup_func_or_method is not 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): def teardown(self):
""" perform teardown for this test function. """ """ perform teardown for this test function. """
@ -345,14 +345,18 @@ class Function(FunctionMixin, py.test.collect.Item):
def runtest(self): def runtest(self):
""" execute the given test function. """ """ execute the given test function. """
if not self._deprecated_testexecution(): self.config.api.pytest_pyfunc_call(pyfuncitem=self,
self.setupargs() # XXX move to setup() / consider funcargs plugin args=self._args, kwargs=self.funcargs)
ret = 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: 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 pass
else: else:
# standard Python Test function/method case # standard Python Test function/method case

View File

@ -20,7 +20,8 @@ def basic_run_report(item, pdb=None):
item.config._setupstate.prepare(item) item.config._setupstate.prepare(item)
try: try:
when = "execute" when = "execute"
res = item.runtest() if not item._deprecated_testexecution():
item.runtest()
finally: finally:
when = "teardown" when = "teardown"
item.config._setupstate.teardown_exact(item) item.config._setupstate.teardown_exact(item)

View File

@ -105,7 +105,7 @@ class TestCollectDeprecated:
funcitem = modcol.collect()[0] funcitem = modcol.collect()[0]
assert funcitem.name == 'test_func' assert funcitem.name == 'test_func'
recwarn.clear() recwarn.clear()
funcitem.runtest() funcitem._deprecated_testexecution()
recwarn.pop(DeprecationWarning) recwarn.pop(DeprecationWarning)
def test_function_custom_execute(self, testdir, recwarn): def test_function_custom_execute(self, testdir, recwarn):

View File

@ -8,7 +8,7 @@ class TestFuncargs:
return 42 return 42
""") """)
item = testdir.getitem("def test_func(some): pass") 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) s = str(exc.value)
assert s.find("xyzsomething") != -1 assert s.find("xyzsomething") != -1
@ -18,7 +18,7 @@ class TestFuncargs:
def pytest_funcarg__some(self, request): def pytest_funcarg__some(self, request):
return request.function.__name__ return request.function.__name__
item.config.pluginmanager.register(Provider()) item.config.pluginmanager.register(Provider())
item.setupargs() item._setupfuncargs()
assert len(item.funcargs) == 1 assert len(item.funcargs) == 1
def test_funcarg_lookup_default_gets_overriden(self, testdir): def test_funcarg_lookup_default_gets_overriden(self, testdir):
@ -27,7 +27,7 @@ class TestFuncargs:
def pytest_funcarg__other(self, request): def pytest_funcarg__other(self, request):
return request.function.__name__ return request.function.__name__
item.config.pluginmanager.register(Provider()) item.config.pluginmanager.register(Provider())
item.setupargs() item._setupfuncargs()
assert len(item.funcargs) == 1 assert len(item.funcargs) == 1
name, value = item.funcargs.popitem() name, value = item.funcargs.popitem()
assert name == "other" assert name == "other"
@ -41,7 +41,7 @@ class TestFuncargs:
def pytest_funcarg__other(self, request): def pytest_funcarg__other(self, request):
return 42 return 42
item.config.pluginmanager.register(Provider()) item.config.pluginmanager.register(Provider())
item.setupargs() item._setupfuncargs()
assert len(item.funcargs) == 2 assert len(item.funcargs) == 2
assert item.funcargs['some'] == "test_func" assert item.funcargs['some'] == "test_func"
assert item.funcargs['other'] == 42 assert item.funcargs['other'] == 42
@ -58,9 +58,9 @@ class TestFuncargs:
pass pass
""") """)
item1, item2 = testdir.genitems([modcol]) item1, item2 = testdir.genitems([modcol])
item1.setupargs() item1._setupfuncargs()
assert item1.funcargs['something'] == "test_method" assert item1.funcargs['something'] == "test_method"
item2.setupargs() item2._setupfuncargs()
assert item2.funcargs['something'] == "test_func" assert item2.funcargs['something'] == "test_func"
class TestRequest: class TestRequest: