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