Commit 52e2f970 authored by Stefan H. Holek's avatar Stefan H. Holek

Modified runalltests.py so it imports modules more like test.py, i.e.

without touching sys.path and without the help of imp.
parent 6f99c00f
......@@ -17,6 +17,8 @@
Reusing the registry from other modules becomes a lot cleaner as a result.
- Made sure to close the REQUEST so as not to leak REQUEST._held. Thanks
to Sidnei da Silva.
- Modified runalltests.py so it imports modules more like test.py, i.e.
without touching sys.path and without the help of imp.
0.9.6
- Dropped support for Zope 2.5 as it lacks the setSecurityManager() API.
......
......@@ -15,38 +15,34 @@
Execute like:
python runalltests.py [-R]
$Id:$
$Id$
"""
__version__ = '0.2.1'
__version__ = '0.3.1'
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
import unittest, imp
import unittest
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
def visitor(recursive, dir, names):
tests = [n[:-3] for n in names if n.startswith('test') and n.endswith('.py')]
for test in tests:
saved_syspath = sys.path[:]
sys.path.insert(0, dir)
try:
fp, path, desc = imp.find_module(test, [dir])
m = imp.load_module(test, fp, path, desc)
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:
modpath = parts + [test[:-3]]
m = __import__('.'.join(modpath))
for part in modpath[1:]:
m = getattr(m, part)
if hasattr(m, 'test_suite'):
suite.addTest(m.test_suite())
finally:
fp.close()
sys.path[:] = saved_syspath
if not recursive:
if not recurse:
names[:] = []
if __name__ == '__main__':
os.path.walk(os.curdir, visitor, '-R' in sys.argv)
os.path.walk(os.curdir, test_finder, '-R' in sys.argv)
TestRunner().run(suite)
......@@ -15,38 +15,34 @@
Execute like:
python runalltests.py [-R]
$Id:$
$Id$
"""
__version__ = '0.2.1'
__version__ = '0.3.1'
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
import unittest, imp
import unittest
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
def visitor(recursive, dir, names):
tests = [n[:-3] for n in names if n.startswith('test') and n.endswith('.py')]
for test in tests:
saved_syspath = sys.path[:]
sys.path.insert(0, dir)
try:
fp, path, desc = imp.find_module(test, [dir])
m = imp.load_module(test, fp, path, desc)
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:
modpath = parts + [test[:-3]]
m = __import__('.'.join(modpath))
for part in modpath[1:]:
m = getattr(m, part)
if hasattr(m, 'test_suite'):
suite.addTest(m.test_suite())
finally:
fp.close()
sys.path[:] = saved_syspath
if not recursive:
if not recurse:
names[:] = []
if __name__ == '__main__':
os.path.walk(os.curdir, visitor, '-R' in sys.argv)
os.path.walk(os.curdir, test_finder, '-R' in sys.argv)
TestRunner().run(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