Error during collection

Issue #53 resolved
Former user created an issue

The following test module causes an error during collection:

{{{

!python

import unittest
class _E(object):
def getattr(self, tag):
pass
E = _E()
}}}

the error:

{{{

!python

(default)l-rjones:foo richard$ py.test
================================================================= test session starts ==================================================================
python: platform darwin -- Python 2.6.1
test object 1: /private/tmp/foo

test_foo.py E

======================================================================== ERRORS ========================================================================
_______ ERROR during collection /private/tmp/foo/test_foo.py _______

collector = <Module 'test_foo.py'>

def pytest_make_collect_report(collector):
    result = excinfo = None
    try:
      result = collector._memocollect()

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/test/plugin/pytest_runner.py:32:


self = <Module 'test_foo.py'>

def _memocollect(self):
    """ internal helper method to cache results of calling collect(). """
  return self._memoizedcall('_collected', self.collect)

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/test/collect.py:300:


self = <Module 'test_foo.py'>, attrname = '_collected', function = <bound method Module.collect of <Module 'test_foo.py'>>

def _memoizedcall(self, attrname, function):
    exattrname = "_ex_" + attrname
    failure = getattr(self, exattrname, None)
    if failure is not None:
        raise failure[0], failure[1], failure[2]
    if hasattr(self, attrname):
        return getattr(self, attrname)
    try:
      res = function()

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/test/collect.py:99:


self = <Module 'test_foo.py'>

def collect(self):
    l = self._deprecated_collect()
    if l is not None:
        return l
  name2items = self._buildname2items()

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/test/pycollect.py:94:


self = <Module 'test_foo.py'>

def _buildname2items(self):
    # NB. we avoid random getattrs and peek in the __dict__ instead
    d = {}
    dicts = [getattr(self.obj, '__dict__', {})]
    for basecls in py.std.inspect.getmro(self.obj.__class__):
        dicts.append(basecls.__dict__)
    seen = {}
    for dic in dicts:
        for name, obj in dic.items():
            if name in seen:
                continue
            seen[name] = True
          res = self.makeitem(name, obj)

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/test/pycollect.py:111:


self = <Module 'test_foo.py'>, name = 'E', obj = <test_foo._E object at 0x758a50>

def makeitem(self, name, obj):
    res = self.config.hook.pytest_pycollect_makeitem(
      collector=self, name=name, obj=obj)

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/test/pycollect.py:123:


self = <HookCaller 'pytest_pycollect_makeitem'>

def __call__(self, **kwargs):
    methods = self.hookrelay._getmethods(self.name, self.extralookup)
    mc = MultiCall(methods, kwargs, firstresult=self.firstresult)
  return self.hookrelay._performcall(self.name, mc)

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/_com.py:120:


self = <py.._com.HookRelay instance at 0x68ef08>, name = 'pytest_pycollect_makeitem'
multicall = <MultiCall 0 results, 0 meths, kwargs={'collector': <Module 'test_foo.py'>, '
multicall__': <MultiCall 0 results, 0 meths, kwargs={...}>, 'obj': <test_foo._E object at 0x758a50>, 'name': 'E'}>

def _performcall(self, name, multicall):
  return multicall.execute()

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/_com.py:105:


self = <MultiCall 0 results, 0 meths, kwargs={'collector': <Module 'test_foo.py'>, 'multicall': <MultiCall 0 results, 0 meths, kwargs={...}>, 'obj': <test_foo._E object at 0x758a50>, 'name': 'E'}>

def execute(self):
    while self.methods:
        method = self.methods.pop()
        kwargs = self.getkwargs(method)
      res = method(**kwargs)

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/_com.py:25:


collector = <Module 'test_foo.py'>, name = 'E', obj = <test_foo._E object at 0x758a50>

def pytest_pycollect_makeitem(collector, name, obj):
    if 'unittest' not in sys.modules:
        return # nobody could have possibly derived a subclass
  if py.std.inspect.isclass(obj) and issubclass(obj, py.std.unittest.TestCase):

E TypeError: issubclass() arg 1 must be a class

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/py/test/plugin/pytest_unittest.py:22: TypeError
=============================================================== 1 error in 0.11 seconds ================================================================
}}}

with py.test version 1.0.2

Comments (2)

  1. Holger Krekel repo owner

    thanks for isolating the problem. I've fixed this interaction in the repository which i soon hope to release as 1.1beta

    on a sidenote, always returning None in a getattr is not suprising to cause inspection troubles and is usually not a good idea. not-provided attributes should raise AttributeError.

    best,holger

  2. Log in to comment