Fixed collection of classes with custom `__new__` method

This commit is contained in:
Dmitry Dygalo
2016-07-23 17:37:58 +02:00
parent d37af20527
commit f7ad173fee
4 changed files with 29 additions and 4 deletions

View File

@@ -662,6 +662,10 @@ class Class(PyCollector):
self.warn("C1", "cannot collect test class %r because it has a "
"__init__ constructor" % self.obj.__name__)
return []
elif hasnew(self.obj):
self.warn("C1", "cannot collect test class %r because it has a "
"__new__ constructor" % self.obj.__name__)
return []
return [self._getcustomclass("Instance")(name="()", parent=self)]
def setup(self):
@@ -679,8 +683,7 @@ class Class(PyCollector):
class Instance(PyCollector):
def _getobj(self):
obj = self.parent.obj()
return obj
return self.parent.obj()
def collect(self):
self.session._fixturemanager.parsefactories(self)
@@ -793,10 +796,14 @@ class Generator(FunctionMixin, PyCollector):
def hasinit(obj):
init = getattr(obj, '__init__', None)
if init:
if init != object.__init__:
return True
return init != object.__init__
def hasnew(obj):
new = getattr(obj, '__new__', None)
if new:
return new != object.__new__
def fillfixtures(function):
""" fill missing funcargs for a test function. """