From ed6d2537bc08e052fcc2fd0084bbf8bb8f50f4ac Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 16 Mar 2011 16:36:18 +0100 Subject: [PATCH] fix issue33 - no collection error for classes prefixed "test" deriving from object --- CHANGELOG | 3 +++ _pytest/python.py | 16 +++++----------- pytest.py | 2 +- setup.py | 2 +- testing/test_python.py | 10 ++++++++++ 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4454409f9..b80c5a66a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ 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 --genscript actually being used. diff --git a/_pytest/python.py b/_pytest/python.py index 61a3f63c9..5378dc095 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -70,11 +70,13 @@ def pytest_pycollect_makeitem(__multicall__, collector, name, obj): res = __multicall__.execute() if res is not None: return res - if collector._istestclasscandidate(name, obj): + if inspect.isclass(obj): #if hasattr(collector.obj, 'unittest'): # return # we assume it's a mixin class for a TestCase derived one - Class = collector._getcustomclass("Class") - return Class(name, parent=collector) + if collector.classnamefilter(name): + if not hasinit(obj): + Class = collector._getcustomclass("Class") + return Class(name, parent=collector) elif collector.funcnamefilter(name) and hasattr(obj, '__call__'): if is_generator(obj): return Generator(name, parent=collector) @@ -194,14 +196,6 @@ class PyCollectorMixin(PyobjMixin, pytest.Collector): return self.ihook.pytest_pycollect_makeitem( 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): module = self.getparent(Module).obj clscol = self.getparent(Class) diff --git a/pytest.py b/pytest.py index 37dd2e0b9..90757b93c 100644 --- a/pytest.py +++ b/pytest.py @@ -1,7 +1,7 @@ """ unit and functional testing with Python. """ -__version__ = '2.0.3.dev1' +__version__ = '2.0.3.dev2' __all__ = ['main'] from _pytest.core import main, UsageError, _preloadplugins diff --git a/setup.py b/setup.py index 562f23c9c..b17306fc5 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.0.3.dev1', + version='2.0.3.dev2', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/test_python.py b/testing/test_python.py index 6c6273b22..5c5ced648 100644 --- a/testing/test_python.py +++ b/testing/test_python.py @@ -46,6 +46,16 @@ class TestClass: l = modcol.collect() 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: def test_generative_functions(self, testdir): modcol = testdir.getmodulecol("""