1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
from _pytest.unittest import UnitTestCase
import sys
def is_unittest(obj):
"""Is obj a subclass of unittest.TestCase?
Lifted from older versions of py.test, as this seems to be removed.
"""
unittest = sys.modules.get('unittest')
if unittest is None:
return # nobody can have derived unittest.TestCase
try:
return issubclass(obj, unittest.TestCase)
except KeyboardInterrupt:
raise
except:
return False
def pytest_pycollect_makeitem(collector, name, obj):
if is_unittest(obj) and not obj.__name__.startswith("_"):
return UnitTestCase(name, parent=collector)
else:
return []
|