[py-svn] py-trunk commit 5b34fb114c30: cleanup: move creation of python colitems to a default pytest_pycollect_makeitem hook impl
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Oct 22 18:38:22 CEST 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1256143360 -7200
# Node ID 5b34fb114c30bbfd6d6c3c8674136ac04897223a
# Parent d9645744d8a5a9f9fefe55698d2513ab966461e3
cleanup: move creation of python colitems to a default pytest_pycollect_makeitem hook impl
--- a/_py/test/pycollect.py
+++ b/_py/test/pycollect.py
@@ -120,24 +120,8 @@ class PyCollectorMixin(PyobjMixin, py.te
return self.join(name)
def makeitem(self, name, obj):
- res = self.config.hook.pytest_pycollect_makeitem(
+ return self.config.hook.pytest_pycollect_makeitem(
collector=self, name=name, obj=obj)
- if res is not None:
- return res
- if self._istestclasscandidate(name, obj):
- res = self._deprecated_join(name)
- if res is not None:
- return res
- return self.Class(name, parent=self)
- elif self.funcnamefilter(name) and hasattr(obj, '__call__'):
- res = self._deprecated_join(name)
- if res is not None:
- return res
- if is_generator(obj):
- # XXX deprecation warning
- return self.Generator(name, parent=self)
- else:
- return self._genfunctions(name, obj)
def _istestclasscandidate(self, name, obj):
if self.classnamefilter(name) and \
@@ -146,7 +130,6 @@ class PyCollectorMixin(PyobjMixin, py.te
# XXX WARN
return False
return True
-
def _genfunctions(self, name, funcobj):
module = self.getparent(Module).obj
@@ -162,12 +145,6 @@ class PyCollectorMixin(PyobjMixin, py.te
return funcargs.FunctionCollector(name=name,
parent=self, calls=metafunc._calls)
-def is_generator(func):
- try:
- return py.code.getrawcode(func).co_flags & 32 # generator function
- except AttributeError: # builtin functions have no bytecode
- # assume them to not be generators
- return False
class Module(py.test.collect.File, PyCollectorMixin):
def _getobj(self):
--- a/_py/test/plugin/pytest_default.py
+++ b/_py/test/plugin/pytest_default.py
@@ -119,3 +119,31 @@ def setsession(config):
elif val("dist") != "no":
from _py.test.dist.dsession import DSession
config.setsessionclass(DSession)
+
+# pycollect related hooks and code, should move to pytest_pycollect.py
+
+def pytest_pycollect_makeitem(__multicall__, collector, name, obj):
+ res = __multicall__.execute()
+ if res is not None:
+ return res
+ if collector._istestclasscandidate(name, obj):
+ res = collector._deprecated_join(name)
+ if res is not None:
+ return res
+ return collector.Class(name, parent=collector)
+ elif collector.funcnamefilter(name) and hasattr(obj, '__call__'):
+ res = collector._deprecated_join(name)
+ if res is not None:
+ return res
+ if is_generator(obj):
+ # XXX deprecation warning
+ return collector.Generator(name, parent=collector)
+ else:
+ return collector._genfunctions(name, obj)
+
+def is_generator(func):
+ try:
+ return py.code.getrawcode(func).co_flags & 32 # generator function
+ except AttributeError: # builtin functions have no bytecode
+ # assume them to not be generators
+ return False
--- a/_py/test/plugin/pytest_unittest.py
+++ b/_py/test/plugin/pytest_unittest.py
@@ -18,7 +18,7 @@ import sys
def pytest_pycollect_makeitem(collector, name, obj):
if 'unittest' not in sys.modules:
- return # nobody could have possibly derived a subclass
+ return # nobody derived unittest.TestCase
try:
isunit = issubclass(obj, py.std.unittest.TestCase)
except TypeError:
More information about the pytest-commit
mailing list