-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_all_tests.py
75 lines (63 loc) · 2.42 KB
/
run_all_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# This file is part of the ISIS IBEX application.
# Copyright (C) 2012-2018 Science & Technology Facilities Council.
# All rights reserved.
#
# This program is distributed in the hope that it will be useful.
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0 which accompanies this distribution.
# EXCEPT AS EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM
# AND ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more details.
#
# You should have received a copy of the Eclipse Public License v1.0
# along with this program; if not, you can obtain a copy from
# https://www.eclipse.org/org/documents/epl-v10.php or
# http://opensource.org/licenses/eclipse-1.0.php
"""
Run all inst server tests
"""
# Standard imports
import argparse
import os
import sys
import unittest
import xmlrunner
from coverage import Coverage
try:
from contextlib import contextmanager, nullcontext
except ImportError:
from contextlib2 import contextmanager, nullcontext
DEFAULT_DIRECTORY = os.path.join("..", "..", "..", "test-reports")
@contextmanager
def coverage_analysis():
cov = Coverage()
cov.start()
try:
yield
finally:
cov.stop()
cov.report()
print("------ SAVING COVERAGE REPORTS ------ ")
cov.xml_report(outfile=os.path.join(".", "cobertura.xml"))
if __name__ == "__main__":
# get output directory from command line arguments
parser = argparse.ArgumentParser()
parser.add_argument(
"-o",
"--output_dir",
nargs=1,
type=str,
default=[DEFAULT_DIRECTORY],
help="The directory to save the test reports",
)
args = parser.parse_args()
xml_dir = args.output_dir[0]
test_suite = unittest.TestLoader().discover(os.path.dirname(__file__), pattern="test_*")
ret_vals = None
# Python 2 coverage analysis does not understand the Py3 code in some modules, and crashes out.
with nullcontext() and coverage_analysis():
print("\n\n------ BEGINNING INST SERVERS UNIT TESTS ------")
ret_vals = xmlrunner.XMLTestRunner(output=xml_dir, verbosity=2).run(test_suite)
print("------ INST SERVERS UNIT TESTS COMPLETE ------\n\n")
# Return failure exit code if a test errored or failed
sys.exit(bool(ret_vals.errors or ret_vals.failures))