-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathruntests.py
55 lines (43 loc) · 1.69 KB
/
runtests.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
import unittest
import xmlrunner
from coverage import Coverage
import sys
"""
Unittest-compatible test-running script
Sonny Rappaport, Cornell June 7/6/2021. Written in conjunction with .circleci/config.yml
to work with circleci's parallelization, coverage.py, and coveralls.
"""
def format_path(file_path):
"""Converts from the default bash /directory/test.py format to directory.test
format (as unittest only works with )
Args:
file_path (String): The name of the file to be formatted. Should be in a
/.../..../test.py format.
"""
no_py = file_path.replace(".py", "")
no_slash = no_py.replace("/", ".")
return no_slash
if __name__ == "__main__":
"""When called via bash with a list of file names, creates and runs a unittest
suite over all the test files passed into this method, generating both a XML
file and a .coverage file for each parallel run on circleci. The XML file is placed
in exosims/test-reports and the XML file is placed in the exosims root folder.
Command line usage example:
python runtests.py [List of testfile names]
"""
cov = Coverage()
cov.start()
loader = unittest.TestLoader()
tests_format = []
for x in sys.argv:
tests_format.append(format_path(x))
# sys.argv (argument from bash) should contain a list of file names
suites = [loader.loadTestsFromName(str) for str in tests_format]
combosuite = unittest.TestSuite(suites)
# create suite of all tests
runner = xmlrunner.XMLTestRunner(output="test-reports")
# generate XML files containing the times of each test for circle-ci's
# test-splitting via time
runner.run(combosuite)
cov.stop()
cov.save()