-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathrun.py
executable file
·75 lines (66 loc) · 1.97 KB
/
run.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
#!/usr/bin/env python
import argparse
import os
import shutil
import sys
from os.path import join
from pathlib import Path
from pytest import main as py_main
CURDIR = Path(__file__).parent
SRC = join(CURDIR, os.pardir, "src")
def remove_output_dir():
output_dir = os.path.join(CURDIR, "output_dir")
if os.path.exists(output_dir):
shutil.rmtree(output_dir)
os.mkdir(output_dir)
def run_unit_tests(reporter, reporter_args, suite, verbose):
sys.path.insert(0, SRC)
suite = CURDIR if not suite else CURDIR / "test" / suite
py_args = [
"--showlocals",
"--tb=long",
f"--rootdir={CURDIR}",
"-p",
"no:cacheprovider",
str(suite),
]
if verbose:
py_args.insert(0, "-v")
if reporter:
py_args.insert(0, f"--approvaltests-add-reporter={reporter}")
if reporter_args:
py_args.insert(1, f"--approvaltests-add-reporter-args={reporter_args}")
try:
result = py_main(py_args)
except Exception as error:
print(f"Suppressed error: {error}")
result = 254
finally:
sys.path.pop(0)
return result
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="SeleniumLibrary Unit test runner.")
parser.add_argument(
"-R", "--approvaltests-use-reporter", default="PythonNative", dest="reporter"
)
parser.add_argument(
"-A", "--approvaltests-add-reporter-args", default=None, dest="reporter_args"
)
parser.add_argument(
"--suite",
"-S",
default="",
help="Select .py file which is only run. Example: locators/test_elementfinder.py or locators/",
)
parser.add_argument(
"--verbose",
dest="verbose",
action="store_true",
default=False,
help="Add verbose output for pytest.",
)
args = parser.parse_args()
remove_output_dir()
sys.exit(
run_unit_tests(args.reporter, args.reporter_args, args.suite, args.verbose)
)