-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·95 lines (84 loc) · 3.26 KB
/
run_tests.py
File metadata and controls
executable file
·95 lines (84 loc) · 3.26 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
"""
To run all tests
python run_tests.py
To run a single test:
python run_tests.py
functional.test_extensions:TestExtensions.test_extensions_json
To run a single test module:
python run_tests.py functional.test_extensions
"""
import logging
import os
import sys
# Configure logging
logging.basicConfig(format='%(levelname)s: %(message)s')
ROOT_LOGGER = logging.getLogger("")
ROOT_LOGGER.setLevel(logging.WARNING)
LOGGER = logging.getLogger(__name__)
# TODO!
TESTS = []
def parse_suite_filter():
""" Parses out -O or --only argument and returns the value after it as the
filter. Removes it from sys.argv in the process. """
suitefilter = None
if '-O' in sys.argv or '--only' in sys.argv:
for i in range(len(sys.argv)):
if sys.argv[i] in ['-O', '--only']:
if len(sys.argv) > i + 1:
# Remove -O/--only settings from sys.argv
sys.argv.pop(i)
suitefilter = sys.argv.pop(i)
break
return suitefilter
if __name__ == '__main__':
SUITE_FILTER = parse_suite_filter()
if SUITE_FILTER:
TESTS = [t for t in TESTS if SUITE_FILTER in str(t)]
if not TESTS:
print 'No test configuration by the name %s found' % SUITE_FILTER
sys.exit(2)
#Run test suites
if len(TESTS) > 1:
CWD_DIRECTORY = os.getcwd()
for test_num, test_cls in enumerate(TESTS):
try:
result = test_cls().run()
if result:
LOGGER.error("Run returned %s for test %s. Exiting" %
(result, test_cls.__name__))
sys.exit(result)
except Exception, e:
print "Error:", e
LOGGER.exception(e)
sys.exit(1)
# Collect coverage from each run. They'll be combined later in .sh
if '--with-coverage' in sys.argv:
coverage_file = os.path.join(CWD_DIRECTORY, ".coverage")
target_file = "%s.%s" % (coverage_file, test_cls.__name__)
try:
if os.path.exists(target_file):
LOGGER.info("deleting %s" % target_file)
os.unlink(target_file)
if os.path.exists(coverage_file):
LOGGER.info("Saving %s to %s" % (coverage_file,
target_file))
os.rename(coverage_file, target_file)
except Exception, e:
LOGGER.exception(e)
print ("Failed to move coverage file while running test"
": %s. Error reported was: %s" %
(test_cls.__name__, e))
sys.exit(1)
else:
for test_num, test_cls in enumerate(TESTS):
try:
result = test_cls().run()
if result:
LOGGER.error("Run returned %s for test %s. Exiting" %
(result, test_cls.__name__))
sys.exit(result)
except Exception, e:
print "Error:", e
LOGGER.exception(e)
sys.exit(1)