summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2007-03-08 12:00:50 +0100
committerAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2007-03-08 12:00:50 +0100
commit73631e1b87f10af78eb87de99681e8cb638cc1d7 (patch)
treef96bef01610c1432a0f07a0c07292ad6add34585
parentb627aed8e75f27ebbf54b345a652f1d1f5db0c3d (diff)
downloadlogilab-common-73631e1b87f10af78eb87de99681e8cb638cc1d7.tar.gz
does python2.3 mean something to you ?
-rw-r--r--pytest.py8
-rw-r--r--testlib.py59
2 files changed, 46 insertions, 21 deletions
diff --git a/pytest.py b/pytest.py
index 29637fb..def2d4f 100644
--- a/pytest.py
+++ b/pytest.py
@@ -16,8 +16,10 @@ unittest._TextTestResult = testlib.SkipAwareTestResult
unittest.TextTestRunner = testlib.SkipAwareTextTestRunner
unittest.TestLoader = testlib.NonStrictTestLoader
unittest.TestProgram = testlib.SkipAwareTestProgram
-doctest.DocTestCase.__bases__ = (testlib.TestCase,)
-
+if sys.version_info >= (2, 4):
+ doctest.DocTestCase.__bases__ = (testlib.TestCase,)
+else:
+ unittest.FunctionTestCase.__bases__ = (testlib.TestCase,)
def autopath(projdir=os.getcwd()):
"""try to find project's root and add it to sys.path"""
@@ -71,7 +73,7 @@ class GlobalTestReport(object):
if self.errors or self.failures:
line2 = '%s modules OK (%s failed)' % (modulesok,
len(self.errmodules))
- descr = ', '.join('%s [%s/%s]' % info for info in self.errmodules)
+ descr = ', '.join(['%s [%s/%s]' % info for info in self.errmodules])
line3 = '\nfailures: %s' % descr
else:
line2 = 'All %s modules OK' % modulesok
diff --git a/testlib.py b/testlib.py
index f64bfbd..9ed6865 100644
--- a/testlib.py
+++ b/testlib.py
@@ -938,24 +938,44 @@ class SkippedSuite(unittest.TestSuite):
self.skipped_test('doctest module has no DocTestSuite class')
-class DocTestFinder(doctest.DocTestFinder):
+# DocTestFinder was introduced in python2.4
+if sys.version_info >= (2, 4):
+ class DocTestFinder(doctest.DocTestFinder):
+
+ def __init__(self, *args, **kwargs):
+ self.skipped = kwargs.pop('skipped', ())
+ doctest.DocTestFinder.__init__(self, *args, **kwargs)
+
+ def _get_test(self, obj, name, module, globs, source_lines):
+ """override default _get_test method to be able to skip tests
+ according to skipped attribute's value
+
+ Note: Python (<=2.4) use a _name_filter which could be used for that
+ purpose but it's no longer available in 2.5
+ Python 2.5 seems to have a [SKIP] flag
+ """
+ if getattr(obj, '__name__', '') in self.skipped:
+ return None
+ return doctest.DocTestFinder._get_test(self, obj, name, module,
+ globs, source_lines)
+else:
+ # this is a hack to make skipped work with python <= 2.3
+ class DocTestFinder(object):
+ def __init__(self, skipped):
+ self.skipped = skipped
+ self.original_find_tests = doctest._find_tests
+ doctest._find_tests = self._find_tests
+
+ def _find_tests(self, module, prefix=None):
+ tests = []
+ for testinfo in self.original_find_tests(module, prefix):
+ testname, _, _, _ = testinfo
+ # testname looks like A.B.C.function_name
+ testname = testname.split('.')[-1]
+ if testname not in self.skipped:
+ tests.append(testinfo)
+ return tests
- def __init__(self, *args, **kwargs):
- self.skipped = kwargs.pop('skipped', ())
- doctest.DocTestFinder.__init__(self, *args, **kwargs)
-
- def _get_test(self, obj, name, module, globs, source_lines):
- """override default _get_test method to be able to skip tests
- according to skipped attribute's value
-
- Note: Python (<=2.4) use a _name_filter which could be used for that
- purpose but it's no longer available in 2.5
- Python 2.5 seems to have a [SKIP] flag
- """
- if getattr(obj, '__name__', '') in self.skipped:
- return None
- return doctest.DocTestFinder._get_test(self, obj, name, module,
- globs, source_lines)
class DocTest(TestCase):
"""trigger module doctest
@@ -966,7 +986,10 @@ class DocTest(TestCase):
def __call__(self, result=None):
try:
finder = DocTestFinder(skipped=self.skipped)
- suite = doctest.DocTestSuite(self.module, test_finder=finder)
+ if sys.version_info >= (2, 4):
+ suite = doctest.DocTestSuite(self.module, test_finder=finder)
+ else:
+ suite = doctest.DocTestSuite(self.module)
except AttributeError:
suite = SkippedSuite()
return suite.run(result)