Commit 67f13e9a authored by Stefan H. Holek's avatar Stefan H. Holek

Merged r69928:69931 from 2.9 branch.

- Nuked the decorator and moved its functionality to the suite factory proper.
- Made runalltests skip 'tests.py' when running ZTC tests.
- Don't run testWebserver.py as part of the Zope2 test suite.
parent 726fc1bc
......@@ -27,12 +27,16 @@ if __name__ == '__main__':
import unittest
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
cwd = os.getcwd()
def test_finder(recurse, dir, names):
if dir == os.curdir or '__init__.py' in names:
parts = [x for x in dir[len(os.curdir):].split(os.sep) if x]
tests = [x for x in names if x.startswith('test') and x.endswith('.py')]
for test in tests:
if test == 'tests.py' and 'ZopeTestCase' in cwd:
# Skip tests.py when running ZTC tests
continue
modpath = parts + [test[:-3]]
m = __import__('.'.join(modpath))
for part in modpath[1:]:
......
"""test runner that works with zope.testing.testrunner"""
import unittest
import os, sys
"""Test runner that works with zope.testing.testrunner"""
import os, sys
import unittest
import os
import Testing.ZopeTestCase
suite = unittest.TestSuite()
names = os.listdir(os.path.dirname(__file__))
tests = [x[:-3] for x in names \
if x.startswith('test') and x.endswith('.py') \
and not x == 'tests.py']
tests = [x[:-3] for x in names
if x.startswith('test') and x.endswith('.py')
and x != 'tests.py'
# Don't run this module as part of the Zope2 suite
and x != 'testWebserver.py']
import Testing.ZopeTestCase
for test in tests:
m = __import__("Testing.ZopeTestCase.%s" %test)
m = __import__('Testing.ZopeTestCase.%s' % test)
m = getattr(Testing.ZopeTestCase, test)
if hasattr(m, 'test_suite'):
suite.addTest(m.test_suite())
......
......@@ -200,15 +200,22 @@ class ZopeSuiteFactory:
def __init__(self, *args, **kw):
self._args = args
self._kw = kw
self._layer = None
self.setup_globs()
self.setup_test_class()
self.setup_optionflags()
def doctestsuite(self):
return doctest.DocTestSuite(*self._args, **self._kw)
suite = doctest.DocTestSuite(*self._args, **self._kw)
if self._layer is not None:
suite.layer = self._layer
return suite
def docfilesuite(self):
return doctest.DocFileSuite(*self._args, **self._kw)
suite = doctest.DocFileSuite(*self._args, **self._kw)
if self._layer is not None:
suite.layer = self._layer
return suite
def setup_globs(self):
globs = self._kw.setdefault('globs', {})
......@@ -224,6 +231,10 @@ class ZopeSuiteFactory:
if 'test_class' in self._kw:
del self._kw['test_class']
# Fix for http://zope.org/Collectors/Zope/2178
if hasattr(test_class, 'layer'):
self._layer = test_class.layer
# If the test_class does not have a runTest method, we add
# a dummy attribute so that TestCase construction works.
if not hasattr(test_class, 'runTest'):
......@@ -299,39 +310,22 @@ class FunctionalSuiteFactory(ZopeSuiteFactory):
| doctest.NORMALIZE_WHITESPACE)
def extractLayer(func):
def wrap(*args, **kw):
suite = func(*args, **kw)
tc = kw.get('test_class', None)
if tc and hasattr(tc, 'layer'):
suite.layer = tc.layer
return suite
return wrap
@extractLayer
def ZopeDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module, depth=3)
module = doctest._normalize_module(module)
return ZopeSuiteFactory(module, **kw).doctestsuite()
@extractLayer
def ZopeDocFileSuite(*paths, **kw):
if kw.get('module_relative', True):
kw['package'] = doctest._normalize_module(kw.get('package'), depth=3)
kw['package'] = doctest._normalize_module(kw.get('package'))
return ZopeSuiteFactory(*paths, **kw).docfilesuite()
@extractLayer
def FunctionalDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module, depth=3)
module = doctest._normalize_module(module)
return FunctionalSuiteFactory(module, **kw).doctestsuite()
@extractLayer
def FunctionalDocFileSuite(*paths, **kw):
if kw.get('module_relative', True):
kw['package'] = doctest._normalize_module(kw.get('package'), depth=3)
kw['package'] = doctest._normalize_module(kw.get('package'))
return FunctionalSuiteFactory(*paths, **kw).docfilesuite()
......
......@@ -27,12 +27,16 @@ if __name__ == '__main__':
import unittest
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
cwd = os.getcwd()
def test_finder(recurse, dir, names):
if dir == os.curdir or '__init__.py' in names:
parts = [x for x in dir[len(os.curdir):].split(os.sep) if x]
tests = [x for x in names if x.startswith('test') and x.endswith('.py')]
for test in tests:
if test == 'tests.py' and 'ZopeTestCase' in cwd:
# Skip tests.py when running ZTC tests
continue
modpath = parts + [test[:-3]]
m = __import__('.'.join(modpath))
for part in modpath[1:]:
......
"""test runner that works with zope.testing.testrunner"""
import unittest
import os, sys
"""Test runner that works with zope.testing.testrunner"""
import os, sys
import unittest
import os
import Testing.ZopeTestCase.zopedoctest
suite = unittest.TestSuite()
names = os.listdir(os.path.dirname(__file__))
tests = [x[:-3] for x in names \
if x.startswith('test') and x.endswith('.py') \
and not x == 'tests.py']
tests = [x[:-3] for x in names
if x.startswith('test') and x.endswith('.py')
and x != 'tests.py']
import Testing.ZopeTestCase.zopedoctest
for test in tests:
m = __import__("Testing.ZopeTestCase.zopedoctest.%s" %test)
m = __import__('Testing.ZopeTestCase.zopedoctest.%s' % test)
m = getattr(Testing.ZopeTestCase.zopedoctest, test)
if hasattr(m, 'test_suite'):
suite.addTest(m.test_suite())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment