2
'''This script runs all tests in a directory.
3
It does not need to know about the tests ahead of time.
4
It recursively descends from the current directory and
5
automatically builds up a list of tests to run.
6
Only directories named 'tests' are processed.
7
The path to each 'tests' directory is added to the PYTHONPATH.
8
Only python scripts that start with 'test_' are added to
9
the list of scripts in the test suite.
14
This license is approved by the OSI and FSF as GPL-compatible.
15
http://opensource.org/licenses/isc-license.txt
17
Copyright (c) 2012, Noah Spurrier <noah@noah.org>
18
PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
19
PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
20
COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
21
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
22
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
23
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
24
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
27
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30
from __future__ import print_function
39
print("Testing pexpect %s using python %s:" % (
40
pexpect.__version__, platform.python_version()))
42
# Don't bother checking performance on Travis, we know it's slow.
43
TEST_PERFORMANCE = 'TRAVIS' not in os.environ
45
def add_tests_to_list (import_list, dirname, names):
46
# Only check directories named 'tests'.
47
if os.path.basename(dirname) != 'tests':
49
# Add any files that start with 'test_' and end with '.py'.
51
filename, ext = os.path.splitext(f)
54
if (not TEST_PERFORMANCE) and (filename == 'test_performance'):
56
if filename.find('test_') == 0:
57
import_list.append (os.path.join(dirname, filename))
59
def find_modules_and_add_paths (root_path):
62
for (dirpath, dirnames, filenames) in os.walk(root_path):
63
add_tests_to_list(import_list, dirpath, filenames)
65
for module_file in import_list:
66
path, module = os.path.split(module_file)
67
module_list.append (module)
68
print('Adding:', os.path.relpath(module_file))
69
if not path in sys.path:
70
sys.path.append (path)
71
if not os.path.dirname(path) in sys.path:
72
sys.path.append (os.path.dirname(path))
78
modules_to_test = find_modules_and_add_paths (os.getcwd())
79
alltests = unittest.TestSuite()
80
for module in map(__import__, modules_to_test):
81
alltests.addTest(unittest.findTestCases(module))
84
if __name__ == '__main__':
85
unittest.main(defaultTest='suite')
87
# runner = unittest.TextTestRunner()