[py-svn] r63868 - in py/trunk/py/test: . testing
hpk at codespeak.net
hpk at codespeak.net
Wed Apr 8 19:42:24 CEST 2009
Author: hpk
Date: Wed Apr 8 19:42:23 2009
New Revision: 63868
Modified:
py/trunk/py/test/pycollect.py
py/trunk/py/test/testing/test_pycollect.py
Log:
move towards having funcarg setup be part of setup()
Modified: py/trunk/py/test/pycollect.py
==============================================================================
--- py/trunk/py/test/pycollect.py (original)
+++ py/trunk/py/test/pycollect.py Wed Apr 8 19:42:23 2009
@@ -327,6 +327,7 @@
super(Function, self).__init__(name, parent, config=config)
self._finalizers = []
self._args = args
+ self.funcargs = {}
if callobj is not _dummy:
self._obj = callobj
@@ -348,13 +349,15 @@
def runtest(self):
""" execute the given test function. """
if not self._deprecated_testexecution():
- kw = self.lookup_allargs()
+ self.setupargs() # XXX move to setup() / consider funcargs plugin
ret = self.config.api.pytest_pyfunc_call(
- pyfuncitem=self, args=self._args, kwargs=kw)
+ pyfuncitem=self, args=self._args, kwargs=self.funcargs)
- def lookup_allargs(self):
- kwargs = {}
- if not self._args:
+ def setupargs(self):
+ if self._args:
+ # generator case: we don't do anything then
+ pass
+ else:
# standard Python Test function/method case
funcobj = self.obj
startindex = getattr(funcobj, 'im_self', None) and 1 or 0
@@ -363,16 +366,13 @@
if i < startindex:
continue
try:
- kwargs[argname] = self.lookup_onearg(argname)
+ self.funcargs[argname] = self.lookup_onearg(argname)
except LookupError, e:
numdefaults = len(funcobj.func_defaults or ())
if i + numdefaults >= len(argnames):
continue # continue # seems that our args have defaults
else:
raise
- else:
- pass # XXX lookup of arguments for yielded/generated tests as well ?
- return kwargs
def lookup_onearg(self, argname):
prefix = "pytest_funcarg__"
Modified: py/trunk/py/test/testing/test_pycollect.py
==============================================================================
--- py/trunk/py/test/testing/test_pycollect.py (original)
+++ py/trunk/py/test/testing/test_pycollect.py Wed Apr 8 19:42:23 2009
@@ -250,7 +250,7 @@
return 42
""")
item = testdir.getitem("def test_func(some): pass")
- exc = py.test.raises(LookupError, "item.lookup_allargs()")
+ exc = py.test.raises(LookupError, "item.setupargs()")
s = str(exc.value)
assert s.find("something") != -1
@@ -260,8 +260,8 @@
def pytest_funcarg__some(self, pyfuncitem):
return pyfuncitem.name
item.config.pytestplugins.register(Provider())
- kw = item.lookup_allargs()
- assert len(kw) == 1
+ item.setupargs()
+ assert len(item.funcargs) == 1
def test_funcarg_lookup_default_gets_overriden(self, testdir):
item = testdir.getitem("def test_func(some=42, other=13): pass")
@@ -269,9 +269,9 @@
def pytest_funcarg__other(self, pyfuncitem):
return pyfuncitem.name
item.config.pytestplugins.register(Provider())
- kw = item.lookup_allargs()
- assert len(kw) == 1
- name, value = kw.popitem()
+ item.setupargs()
+ assert len(item.funcargs) == 1
+ name, value = item.funcargs.popitem()
assert name == "other"
assert value == item.name
@@ -283,10 +283,10 @@
def pytest_funcarg__other(self, pyfuncitem):
return 42
item.config.pytestplugins.register(Provider())
- kw = item.lookup_allargs()
- assert len(kw) == 2
- assert kw['some'] == "test_func"
- assert kw['other'] == 42
+ item.setupargs()
+ assert len(item.funcargs) == 2
+ assert item.funcargs['some'] == "test_func"
+ assert item.funcargs['other'] == 42
def test_funcarg_addfinalizer(self, testdir):
item = testdir.getitem("def test_func(some): pass")
@@ -296,9 +296,9 @@
pyfuncitem.addfinalizer(lambda: l.append(42))
return 3
item.config.pytestplugins.register(Provider())
- kw = item.lookup_allargs()
- assert len(kw) == 1
- assert kw['some'] == 3
+ item.setupargs()
+ assert len(item.funcargs) == 1
+ assert item.funcargs['some'] == 3
assert len(l) == 0
item.teardown()
assert len(l) == 1
@@ -318,10 +318,10 @@
item1, item2 = testdir.genitems([modcol])
modcol.setup()
assert modcol.config.pytestplugins.isregistered(modcol.obj)
- kwargs = item1.lookup_allargs()
- assert kwargs['something'] == "test_method"
- kwargs = item2.lookup_allargs()
- assert kwargs['something'] == "test_func"
+ item1.setupargs()
+ assert item1.funcargs['something'] == "test_method"
+ item2.setupargs()
+ assert item2.funcargs['something'] == "test_func"
modcol.teardown()
assert not modcol.config.pytestplugins.isregistered(modcol.obj)
More information about the pytest-commit
mailing list