fix issue33 - no collection error for classes prefixed "test" deriving from object

This commit is contained in:
holger krekel 2011-03-16 16:36:18 +01:00
parent a9f1f26a39
commit ed6d2537bc
5 changed files with 20 additions and 13 deletions

View File

@ -1,6 +1,9 @@
Changes between 2.0.2 and 2.0.3.dev Changes between 2.0.2 and 2.0.3.dev
---------------------------------------------- ----------------------------------------------
- fix issue34: avoid collection failure with "test" prefixed classes
deriving from object.
- don't require zlib (and other libs) for genscript plugin without - don't require zlib (and other libs) for genscript plugin without
--genscript actually being used. --genscript actually being used.

View File

@ -70,9 +70,11 @@ def pytest_pycollect_makeitem(__multicall__, collector, name, obj):
res = __multicall__.execute() res = __multicall__.execute()
if res is not None: if res is not None:
return res return res
if collector._istestclasscandidate(name, obj): if inspect.isclass(obj):
#if hasattr(collector.obj, 'unittest'): #if hasattr(collector.obj, 'unittest'):
# return # we assume it's a mixin class for a TestCase derived one # return # we assume it's a mixin class for a TestCase derived one
if collector.classnamefilter(name):
if not hasinit(obj):
Class = collector._getcustomclass("Class") Class = collector._getcustomclass("Class")
return Class(name, parent=collector) return Class(name, parent=collector)
elif collector.funcnamefilter(name) and hasattr(obj, '__call__'): elif collector.funcnamefilter(name) and hasattr(obj, '__call__'):
@ -194,14 +196,6 @@ class PyCollectorMixin(PyobjMixin, pytest.Collector):
return self.ihook.pytest_pycollect_makeitem( return self.ihook.pytest_pycollect_makeitem(
collector=self, name=name, obj=obj) collector=self, name=name, obj=obj)
def _istestclasscandidate(self, name, obj):
if self.classnamefilter(name) and \
inspect.isclass(obj):
if hasinit(obj):
# XXX WARN
return False
return True
def _genfunctions(self, name, funcobj): def _genfunctions(self, name, funcobj):
module = self.getparent(Module).obj module = self.getparent(Module).obj
clscol = self.getparent(Class) clscol = self.getparent(Class)

View File

@ -1,7 +1,7 @@
""" """
unit and functional testing with Python. unit and functional testing with Python.
""" """
__version__ = '2.0.3.dev1' __version__ = '2.0.3.dev2'
__all__ = ['main'] __all__ = ['main']
from _pytest.core import main, UsageError, _preloadplugins from _pytest.core import main, UsageError, _preloadplugins

View File

@ -22,7 +22,7 @@ def main():
name='pytest', name='pytest',
description='py.test: simple powerful testing with Python', description='py.test: simple powerful testing with Python',
long_description = long_description, long_description = long_description,
version='2.0.3.dev1', version='2.0.3.dev2',
url='http://pytest.org', url='http://pytest.org',
license='MIT license', license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

View File

@ -46,6 +46,16 @@ class TestClass:
l = modcol.collect() l = modcol.collect()
assert len(l) == 0 assert len(l) == 0
def test_class_subclassobject(self, testdir):
testdir.getmodulecol("""
class test(object):
pass
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines([
"*collected 0*",
])
class TestGenerator: class TestGenerator:
def test_generative_functions(self, testdir): def test_generative_functions(self, testdir):
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""