This repository has been archived by the owner on Apr 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
run_tests.py
52 lines (41 loc) · 1.44 KB
/
run_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
import optparse
import os
import sys
import unittest2
USAGE = """%prog SDK_PATH TEST_PATH
Run unit tests for App Engine apps.
SDK_PATH Path to the SDK installation
TEST_PATH Path to package containing test modules"""
def main(sdk_path, test_paths):
if 'lib' not in sys.path:
sys.path.insert(0, 'lib')
sys.path.insert(0, sdk_path)
import dev_appserver
dev_appserver.fix_sys_path()
suites = unittest2.TestSuite()
for test_path in test_paths:
suite = None
# tests/ directory
if os.path.isdir(test_path):
suite = unittest2.loader.TestLoader().discover(test_path)
# test_file.py
elif os.path.isfile(test_path):
test_path, test_file = test_path.rsplit(os.path.sep, 1)
suite = unittest2.loader.TestLoader().discover(test_path, test_file)
# tests.module.TestCase
elif '/' not in test_path and '.' in test_path:
suite = unittest2.loader.TestLoader().loadTestsFromName(test_path)
if suite is not None:
suites.addTest(suite)
unittest2.TextTestRunner(verbosity=2).run(suites)
if __name__ == '__main__':
parser = optparse.OptionParser(USAGE)
options, args = parser.parse_args()
if len(args) < 2:
print 'Error: At least 2 arguments required.'
parser.print_help()
sys.exit(1)
SDK_PATH = args[0]
TEST_PATHS = args[1:]
main(SDK_PATH, TEST_PATHS)