resolves #59 - robustify unittest collection

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-10-09 15:09:26 +02:00
parent a603021757
commit f10bfbb7e5
3 changed files with 20 additions and 3 deletions

View File

@ -19,8 +19,13 @@ import sys
def pytest_pycollect_makeitem(collector, name, obj): def pytest_pycollect_makeitem(collector, name, obj):
if 'unittest' not in sys.modules: if 'unittest' not in sys.modules:
return # nobody could have possibly derived a subclass return # nobody could have possibly derived a subclass
if py.std.inspect.isclass(obj) and issubclass(obj, py.std.unittest.TestCase): try:
return UnitTestCase(name, parent=collector) isunit = issubclass(obj, py.std.unittest.TestCase)
except TypeError:
pass
else:
if isunit:
return UnitTestCase(name, parent=collector)
class UnitTestCase(py.test.collect.Class): class UnitTestCase(py.test.collect.Class):
def collect(self): def collect(self):

View File

@ -1,6 +1,8 @@
Changes between 1.0.2 and '1.1.0b1' Changes between 1.0.2 and '1.1.0b1'
===================================== =====================================
* fix issue #59 - robustify unittest test collection
* make bpython/help interaction work by adding an __all__ attribute * make bpython/help interaction work by adding an __all__ attribute
to ApiModule, cleanup initpkg to ApiModule, cleanup initpkg

View File

@ -1,6 +1,5 @@
import py import py
def test_simple_unittest(testdir): def test_simple_unittest(testdir):
testpath = testdir.makepyfile(""" testpath = testdir.makepyfile("""
import unittest import unittest
@ -15,6 +14,17 @@ def test_simple_unittest(testdir):
assert reprec.matchreport("testpassing").passed assert reprec.matchreport("testpassing").passed
assert reprec.matchreport("test_failing").failed assert reprec.matchreport("test_failing").failed
def test_isclasscheck_issue53(testdir):
testpath = testdir.makepyfile("""
import unittest
class _E(object):
def __getattr__(self, tag):
pass
E = _E()
""")
result = testdir.runpytest(testpath)
assert result.ret == 0
def test_setup(testdir): def test_setup(testdir):
testpath = testdir.makepyfile(test_two=""" testpath = testdir.makepyfile(test_two="""
import unittest import unittest