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__': ...@@ -27,12 +27,16 @@ if __name__ == '__main__':
import unittest import unittest
TestRunner = unittest.TextTestRunner TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite() suite = unittest.TestSuite()
cwd = os.getcwd()
def test_finder(recurse, dir, names): def test_finder(recurse, dir, names):
if dir == os.curdir or '__init__.py' in names: if dir == os.curdir or '__init__.py' in names:
parts = [x for x in dir[len(os.curdir):].split(os.sep) if x] 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')] tests = [x for x in names if x.startswith('test') and x.endswith('.py')]
for test in tests: for test in tests:
if test == 'tests.py' and 'ZopeTestCase' in cwd:
# Skip tests.py when running ZTC tests
continue
modpath = parts + [test[:-3]] modpath = parts + [test[:-3]]
m = __import__('.'.join(modpath)) m = __import__('.'.join(modpath))
for part in modpath[1:]: for part in modpath[1:]:
......
"""test runner that works with zope.testing.testrunner""" """Test runner that works with zope.testing.testrunner"""
import unittest
import os, sys
import os, sys import unittest
import os
import Testing.ZopeTestCase
suite = unittest.TestSuite() suite = unittest.TestSuite()
names = os.listdir(os.path.dirname(__file__)) names = os.listdir(os.path.dirname(__file__))
tests = [x[:-3] for x in names \ tests = [x[:-3] for x in names
if x.startswith('test') and x.endswith('.py') \ if x.startswith('test') and x.endswith('.py')
and not x == 'tests.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: for test in tests:
m = __import__("Testing.ZopeTestCase.%s" %test) m = __import__('Testing.ZopeTestCase.%s' % test)
m = getattr(Testing.ZopeTestCase, test) m = getattr(Testing.ZopeTestCase, test)
if hasattr(m, 'test_suite'): if hasattr(m, 'test_suite'):
suite.addTest(m.test_suite()) suite.addTest(m.test_suite())
......
...@@ -200,15 +200,22 @@ class ZopeSuiteFactory: ...@@ -200,15 +200,22 @@ class ZopeSuiteFactory:
def __init__(self, *args, **kw): def __init__(self, *args, **kw):
self._args = args self._args = args
self._kw = kw self._kw = kw
self._layer = None
self.setup_globs() self.setup_globs()
self.setup_test_class() self.setup_test_class()
self.setup_optionflags() self.setup_optionflags()
def doctestsuite(self): 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): 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): def setup_globs(self):
globs = self._kw.setdefault('globs', {}) globs = self._kw.setdefault('globs', {})
...@@ -224,6 +231,10 @@ class ZopeSuiteFactory: ...@@ -224,6 +231,10 @@ class ZopeSuiteFactory:
if 'test_class' in self._kw: if 'test_class' in self._kw:
del self._kw['test_class'] 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 # If the test_class does not have a runTest method, we add
# a dummy attribute so that TestCase construction works. # a dummy attribute so that TestCase construction works.
if not hasattr(test_class, 'runTest'): if not hasattr(test_class, 'runTest'):
...@@ -299,39 +310,22 @@ class FunctionalSuiteFactory(ZopeSuiteFactory): ...@@ -299,39 +310,22 @@ class FunctionalSuiteFactory(ZopeSuiteFactory):
| doctest.NORMALIZE_WHITESPACE) | 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): def ZopeDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module, depth=3) module = doctest._normalize_module(module)
return ZopeSuiteFactory(module, **kw).doctestsuite() return ZopeSuiteFactory(module, **kw).doctestsuite()
@extractLayer
def ZopeDocFileSuite(*paths, **kw): def ZopeDocFileSuite(*paths, **kw):
if kw.get('module_relative', True): 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() return ZopeSuiteFactory(*paths, **kw).docfilesuite()
@extractLayer
def FunctionalDocTestSuite(module=None, **kw): def FunctionalDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module, depth=3) module = doctest._normalize_module(module)
return FunctionalSuiteFactory(module, **kw).doctestsuite() return FunctionalSuiteFactory(module, **kw).doctestsuite()
@extractLayer
def FunctionalDocFileSuite(*paths, **kw): def FunctionalDocFileSuite(*paths, **kw):
if kw.get('module_relative', True): 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() return FunctionalSuiteFactory(*paths, **kw).docfilesuite()
......
...@@ -27,12 +27,16 @@ if __name__ == '__main__': ...@@ -27,12 +27,16 @@ if __name__ == '__main__':
import unittest import unittest
TestRunner = unittest.TextTestRunner TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite() suite = unittest.TestSuite()
cwd = os.getcwd()
def test_finder(recurse, dir, names): def test_finder(recurse, dir, names):
if dir == os.curdir or '__init__.py' in names: if dir == os.curdir or '__init__.py' in names:
parts = [x for x in dir[len(os.curdir):].split(os.sep) if x] 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')] tests = [x for x in names if x.startswith('test') and x.endswith('.py')]
for test in tests: for test in tests:
if test == 'tests.py' and 'ZopeTestCase' in cwd:
# Skip tests.py when running ZTC tests
continue
modpath = parts + [test[:-3]] modpath = parts + [test[:-3]]
m = __import__('.'.join(modpath)) m = __import__('.'.join(modpath))
for part in modpath[1:]: for part in modpath[1:]:
......
"""test runner that works with zope.testing.testrunner""" """Test runner that works with zope.testing.testrunner"""
import unittest
import os, sys
import os, sys import unittest
import os
import Testing.ZopeTestCase.zopedoctest
suite = unittest.TestSuite() suite = unittest.TestSuite()
names = os.listdir(os.path.dirname(__file__)) names = os.listdir(os.path.dirname(__file__))
tests = [x[:-3] for x in names \ tests = [x[:-3] for x in names
if x.startswith('test') and x.endswith('.py') \ if x.startswith('test') and x.endswith('.py')
and not x == 'tests.py'] and x != 'tests.py']
import Testing.ZopeTestCase.zopedoctest
for test in tests: for test in tests:
m = __import__("Testing.ZopeTestCase.zopedoctest.%s" %test) m = __import__('Testing.ZopeTestCase.zopedoctest.%s' % test)
m = getattr(Testing.ZopeTestCase.zopedoctest, test) m = getattr(Testing.ZopeTestCase.zopedoctest, test)
if hasattr(m, 'test_suite'): if hasattr(m, 'test_suite'):
suite.addTest(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