Skip to content

Commit d9fb52a

Browse files
authored
Rework test runners to centralized workflow (#2996)
1 parent e3f9f5a commit d9fb52a

File tree

3 files changed

+75
-11
lines changed

3 files changed

+75
-11
lines changed

scripts/ci/run-crt-tests

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
# Don't run tests from the root repo dir.
3+
# We want to ensure we're importing from the installed
4+
# binary package not from the CWD.
5+
6+
import os
7+
import sys
8+
from subprocess import check_call
9+
10+
_dname = os.path.dirname
11+
12+
REPO_ROOT = _dname(_dname(_dname(os.path.abspath(__file__))))
13+
os.chdir(os.path.join(REPO_ROOT, "tests"))
14+
15+
16+
def run(command):
17+
return check_call(command, shell=True)
18+
19+
20+
try:
21+
import awscrt
22+
except ImportError:
23+
print("MISSING DEPENDENCY: awscrt must be installed to run the crt tests.")
24+
sys.exit(1)
25+
26+
run(f'{REPO_ROOT}/scripts/ci/run-tests unit/ functional/')

scripts/ci/run-integ-tests

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ from subprocess import check_call
99
_dname = os.path.dirname
1010

1111
REPO_ROOT = _dname(_dname(_dname(os.path.abspath(__file__))))
12-
os.chdir(os.path.join(REPO_ROOT, 'tests'))
12+
os.chdir(os.path.join(REPO_ROOT, "tests"))
1313

1414

1515
def run(command):
1616
return check_call(command, shell=True)
1717

1818

19-
run('nosetests --with-xunit --cover-erase --with-coverage '
20-
'--cover-package boto3 --cover-xml -v integration')
19+
run(f"{REPO_ROOT}/scripts/ci/run-tests --with-cov integration")

scripts/ci/run-tests

+47-8
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,58 @@
33
# We want to ensure we're importing from the installed
44
# binary package not from the CWD.
55

6+
import argparse
67
import os
7-
import sys
88
from subprocess import check_call
99

1010
_dname = os.path.dirname
1111

1212
REPO_ROOT = _dname(_dname(_dname(os.path.abspath(__file__))))
13-
os.chdir(os.path.join(REPO_ROOT, 'tests'))
13+
PACKAGE = "boto3"
14+
os.chdir(os.path.join(REPO_ROOT, "tests"))
1415

15-
args = sys.argv[1:]
16-
if not args:
17-
args = ['unit/', 'functional/']
1816

19-
check_call(['nosetests', '--with-coverage', '--cover-erase',
20-
'--cover-package', 'boto3', '--with-xunit', '--cover-xml',
21-
'-v'] + args)
17+
def run(command):
18+
return check_call(command, shell=True)
19+
20+
21+
def process_args(args):
22+
runner = args.test_runner
23+
test_args = ''
24+
if args.with_cov:
25+
test_args += (
26+
f"--with-xunit --cover-erase --with-coverage "
27+
f"--cover-package {PACKAGE} --cover-xml -v "
28+
)
29+
dirs = " ".join(args.test_dirs)
30+
31+
return runner, test_args, dirs
32+
33+
34+
if __name__ == "__main__":
35+
parser = argparse.ArgumentParser()
36+
parser.add_argument(
37+
"test_dirs",
38+
default=["unit/", "functional/"],
39+
nargs="*",
40+
help="One or more directories containing tests.",
41+
)
42+
parser.add_argument(
43+
"-r",
44+
"--test-runner",
45+
default="nosetests",
46+
help="Test runner to execute tests. Defaults to nose.",
47+
)
48+
parser.add_argument(
49+
"-c",
50+
"--with-cov",
51+
default=False,
52+
action="store_true",
53+
help="Run default test-runner with code coverage enabled.",
54+
)
55+
raw_args = parser.parse_args()
56+
test_runner, test_args, test_dirs = process_args(raw_args)
57+
58+
cmd = f"{test_runner} {test_args}{test_dirs}"
59+
print(f"Running {cmd}...")
60+
run(cmd)

0 commit comments

Comments
 (0)