Test* classes with an __init__ method are not collected anymore
--HG-- branch : 1.0.x
This commit is contained in:
parent
58c6971dc8
commit
d41949a6e3
|
@ -8,6 +8,8 @@ Changes between 1.0.0 and 1.0.1
|
||||||
* fix issue #27: better reporting on non-collectable items given on commandline
|
* fix issue #27: better reporting on non-collectable items given on commandline
|
||||||
(e.g. pyc files)
|
(e.g. pyc files)
|
||||||
|
|
||||||
|
* "Test" prefixed classes with an __init__ method are *not* collected by default anymore
|
||||||
|
|
||||||
* terser reporting of collection error tracebacks
|
* terser reporting of collection error tracebacks
|
||||||
|
|
||||||
* renaming of arguments to some special rather internal hooks
|
* renaming of arguments to some special rather internal hooks
|
||||||
|
|
|
@ -125,18 +125,12 @@ def test_func_generator_setup(testdir):
|
||||||
def test_method_setup_uses_fresh_instances(testdir):
|
def test_method_setup_uses_fresh_instances(testdir):
|
||||||
reprec = testdir.inline_runsource("""
|
reprec = testdir.inline_runsource("""
|
||||||
class TestSelfState1:
|
class TestSelfState1:
|
||||||
def __init__(self):
|
memory = []
|
||||||
self.hello = 42
|
|
||||||
def test_hello(self):
|
def test_hello(self):
|
||||||
self.world = 23
|
self.memory.append(self)
|
||||||
def test_afterhello(self):
|
|
||||||
assert not hasattr(self, 'world')
|
def test_afterhello(self):
|
||||||
assert self.hello == 42
|
assert self != self.memory[0]
|
||||||
class TestSelfState2:
|
""")
|
||||||
def test_hello(self):
|
reprec.assertoutcome(passed=2, failed=0)
|
||||||
self.world = 10
|
|
||||||
def test_world(self):
|
|
||||||
assert not hasattr(self, 'world')
|
|
||||||
""")
|
|
||||||
reprec.assertoutcome(passed=4, failed=0)
|
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,7 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
|
||||||
collector=self, name=name, obj=obj)
|
collector=self, name=name, obj=obj)
|
||||||
if res is not None:
|
if res is not None:
|
||||||
return res
|
return res
|
||||||
if (self.classnamefilter(name)) and \
|
if self._istestclasscandidate(name, obj):
|
||||||
py.std.inspect.isclass(obj):
|
|
||||||
res = self._deprecated_join(name)
|
res = self._deprecated_join(name)
|
||||||
if res is not None:
|
if res is not None:
|
||||||
return res
|
return res
|
||||||
|
@ -139,14 +138,25 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
|
||||||
else:
|
else:
|
||||||
return self._genfunctions(name, obj)
|
return self._genfunctions(name, obj)
|
||||||
|
|
||||||
|
def _istestclasscandidate(self, name, obj):
|
||||||
|
if self.classnamefilter(name) and \
|
||||||
|
py.std.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
|
||||||
# due to _buildname2items funcobj is the raw function, we need
|
# due to _buildname2items funcobj is the raw function, we need
|
||||||
# to work to get at the class
|
# to work to get at the class
|
||||||
clscol = self.getparent(Class)
|
clscol = self.getparent(Class)
|
||||||
cls = clscol and clscol.obj or None
|
cls = clscol and clscol.obj or None
|
||||||
metafunc = funcargs.Metafunc(funcobj, config=self.config, cls=cls, module=module)
|
metafunc = funcargs.Metafunc(funcobj, config=self.config,
|
||||||
gentesthook = self.config.hook.pytest_generate_tests.clone(extralookup=module)
|
cls=cls, module=module)
|
||||||
|
gentesthook = self.config.hook.pytest_generate_tests.clone(
|
||||||
|
extralookup=module)
|
||||||
gentesthook(metafunc=metafunc)
|
gentesthook(metafunc=metafunc)
|
||||||
if not metafunc._calls:
|
if not metafunc._calls:
|
||||||
return self.Function(name, parent=self)
|
return self.Function(name, parent=self)
|
||||||
|
@ -371,3 +381,9 @@ class Function(FunctionMixin, py.test.collect.Item):
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return not self == other
|
return not self == other
|
||||||
|
|
||||||
|
|
||||||
|
def hasinit(obj):
|
||||||
|
init = getattr(obj, '__init__', None)
|
||||||
|
if init:
|
||||||
|
if not isinstance(init, type(object.__init__)):
|
||||||
|
return True
|
||||||
|
|
|
@ -39,6 +39,19 @@ class TestModule:
|
||||||
modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',")
|
modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',")
|
||||||
py.test.raises(ImportError, "modcol.obj")
|
py.test.raises(ImportError, "modcol.obj")
|
||||||
|
|
||||||
|
class TestClass:
|
||||||
|
def test_class_with_init_not_collected(self, testdir):
|
||||||
|
modcol = testdir.getmodulecol("""
|
||||||
|
class TestClass1:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
class TestClass2(object):
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
l = modcol.collect()
|
||||||
|
assert len(l) == 0
|
||||||
|
|
||||||
class TestDisabled:
|
class TestDisabled:
|
||||||
def test_disabled_module(self, testdir):
|
def test_disabled_module(self, testdir):
|
||||||
modcol = testdir.getmodulecol("""
|
modcol = testdir.getmodulecol("""
|
||||||
|
|
Loading…
Reference in New Issue