[py-svn] r62081 - in py/branch/pytestplugin/py/test: . plugin testing
hpk at codespeak.net
hpk at codespeak.net
Sat Feb 21 18:44:29 CET 2009
Author: hpk
Date: Sat Feb 21 18:44:25 2009
New Revision: 62081
Modified:
py/branch/pytestplugin/py/test/plugin/pytest_tmpdir.py
py/branch/pytestplugin/py/test/pycollect.py
py/branch/pytestplugin/py/test/testing/test_pycollect.py
Log:
add addfinalizer method and check for proper exception
Modified: py/branch/pytestplugin/py/test/plugin/pytest_tmpdir.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_tmpdir.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_tmpdir.py Sat Feb 21 18:44:25 2009
@@ -14,7 +14,7 @@
to test functions and methods.
"""
def pytest_pyfunc_arg(self, pyfuncitem, argname):
- print "tmpdir: receiving call", pyfuncitem, argname
+ #print "tmpdir: receiving call", pyfuncitem, argname
if argname == "tmpdir":
basename = "_".join(pyfuncitem.listnames())
# move to config
Modified: py/branch/pytestplugin/py/test/pycollect.py
==============================================================================
--- py/branch/pytestplugin/py/test/pycollect.py (original)
+++ py/branch/pytestplugin/py/test/pycollect.py Sat Feb 21 18:44:25 2009
@@ -316,11 +316,21 @@
"""
def __init__(self, name, parent=None, config=None, args=(), callobj=_dummy):
super(Function, self).__init__(name, parent, config=config)
- self._argfinalizers = []
+ self._finalizers = []
self._args = args
if callobj is not _dummy:
self._obj = callobj
+ def addfinalizer(self, func):
+ self._finalizers.append(func)
+
+ def teardown(self):
+ finalizers = self._finalizers
+ while finalizers:
+ call = finalizers.pop()
+ call()
+ super(Function, self).teardown()
+
def readkeywords(self):
d = super(Function, self).readkeywords()
d.update(self.obj.func_dict)
@@ -336,13 +346,6 @@
return
self.obj(*self._args, **kw)
- def teardown(self):
- finalizers = self._argfinalizers
- while finalizers:
- call = finalizers.pop()
- call()
- super(Function, self).teardown()
-
def lookup_allargs(self):
kwargs = {}
if not self._args:
@@ -361,12 +364,7 @@
if value is not None:
return value
else:
- print "pytestplugins is", self._config.pytestplugins
- print "could not find argument %r, plugins=%r" %(
- argname,self._config.pytestplugins._plugins)
- for x in call.methods:
- print x
- raise TypeError("could not provide funcargument %r" %(argname,))
+ raise LookupError("could not provide funcargument %r" %(argname,))
def getkwargs(self):
kwargs = {}
Modified: py/branch/pytestplugin/py/test/testing/test_pycollect.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_pycollect.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_pycollect.py Sat Feb 21 18:44:25 2009
@@ -217,6 +217,10 @@
assert f1 == f1_b
assert not f1 != f1_b
+ def test_pyfuncarg_lookupfails(self, testdir):
+ item = testdir.getitem("def test_func(some, other): pass")
+ kw = py.test.raises(LookupError, "item.lookup_allargs()")
+
def test_pyfuncarg_basic(self, testdir):
item = testdir.getitem("def test_func(some, other): pass")
class Provider:
@@ -230,6 +234,22 @@
assert kw['some'] == "test_func"
assert kw['other'] == 42
+ def test_pyfuncarg_finalize(self, testdir):
+ item = testdir.getitem("def test_func(some): pass")
+ l = []
+ class Provider:
+ def pytest_pyfuncarg_some(self, pyfuncitem):
+ 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
+ assert len(l) == 0
+ item.teardown()
+ assert len(l) == 1
+ assert l[0] == 42
+
class TestSorting:
def test_check_equality_and_cmp_basic(self, testdir):
modcol = testdir.getmodulecol("""
More information about the pytest-commit
mailing list