-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.py
60 lines (47 loc) · 1.89 KB
/
run_test.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
import unittest
import argparse
import sys
import os
import xmlrunner
def create_test_suite_from_specs(loader, specs):
if "**" in specs:
# folder execution
testsuite = loader.discover(specs[:specs.find("**")], "*.py")
else:
# single file execution
mod_name = os.path.relpath(specs).replace(os.path.sep,
".").replace(".py", "")
testsuite = loader.loadTestsFromNames([mod_name])
return testsuite
def create_test_suite_from_grep(loader, grep):
mod_name = os.path.relpath(grep).replace(os.path.sep,
".").replace(".py", "")
testsuite = loader.loadTestsFromName(mod_name)
return testsuite
def main():
parser = argparse.ArgumentParser(
description='Sencha WebtestIt Python scaffold')
parser.add_argument("--specs", type=str)
parser.add_argument("--grep", type=str)
args = parser.parse_args()
loader = unittest.TestLoader()
if hasattr(args, "specs") and args.specs is not None:
testsuite = create_test_suite_from_specs(loader, args.specs)
elif hasattr(args, "grep") and args.grep is not None:
testsuite = create_test_suite_from_grep(loader, args.grep)
else:
# discover looks by default for files named in the pattern test_*
testsuite = loader.discover("./tests", "*.py")
if not os.path.exists("temp-reports"):
os.mkdir("temp-reports")
# JUnit reports generated in test-reports folder
with open(
os.path.join("temp-reports/",
os.environ.get("TEST_REPORT_FILENAME")),
"wb") as output:
result = xmlrunner.XMLTestRunner(output=output,
stream=sys.stdout).run(testsuite)
result.shouldStop = False
sys.exit(not result.wasSuccessful())
if __name__ == "__main__":
main()