Skip to content

Commit b7af722

Browse files
author
chad8242310
committed
updated test runner
1 parent cfa0b14 commit b7af722

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ dmypy.json
135135
# MacOS
136136
.DS_Store
137137

138-
# Testing Directories
138+
# Testing Files and Directories
139+
tests/*.log
139140
tests/.pytest_cache/
140141
tests/reports/
141-
tests/*.log
142+
tests/logs/

scripts/runtests.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"""
1313
from __future__ import absolute_import, print_function, unicode_literals
1414

15+
import logging
1516
import os
1617
from contextlib import contextmanager
1718
from errno import EEXIST
@@ -96,6 +97,23 @@ def mkdir_p(path):
9697
raise
9798

9899

100+
def mkdirs_p(*path):
101+
"""Create multiple directories.
102+
103+
Notes:
104+
Unix "mkdir -p" equivalent.
105+
106+
Args:
107+
path (str): Filepaths to create.
108+
109+
Raises:
110+
OSError: Raised for exceptions unrelated to the
111+
directory already existing.
112+
"""
113+
for p in path:
114+
mkdir_p(p)
115+
116+
99117
def touch(filepath):
100118
"""Equivalent of Unix `touch` command.
101119
@@ -118,37 +136,31 @@ def main():
118136
Returns:
119137
int: Command return code.
120138
"""
139+
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s")
140+
121141
repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
122142
module = module_name(where=repo_root)
143+
logging.debug("running tests for module: %s", module)
123144

124145
return_code = -1 # noqa
146+
125147
with cwd(repo_root):
148+
# noinspection PyUnusedLocal
126149
env_name = os.getenv("ENVNAME", "test")
127150

128151
tests_dir = os.path.join(repo_root, "tests")
129152
logs_dir = os.path.join(tests_dir, "logs")
130-
mkdir_p(logs_dir)
131-
153+
reports_dir = os.path.join(tests_dir, "reports")
132154
tests_log_file = os.path.join(logs_dir, "pytest.log")
155+
156+
mkdirs_p(logs_dir, reports_dir)
133157
touch(tests_log_file) # prevent pytest error due to missing log file
134158

135-
reports_dir = os.path.join(tests_dir, "reports")
136-
mkdir_p(reports_dir)
137-
138-
tests_html_filename = "{0!s}.html".format(env_name)
139-
tests_html_file = os.path.join(reports_dir, tests_html_filename)
140-
141-
return_code = run(
142-
"pytest {posargs} "
143-
"--cov={module} "
144-
"--html={tests_html_file} "
145-
"--self-contained-html".format(
146-
module=module,
147-
tests_html_file=tests_html_file,
148-
envname=env_name,
149-
posargs=tests_dir
150-
)
151-
)
159+
return_code = run("pytest {posargs} --cov={module}".format(
160+
posargs=tests_dir,
161+
module=module
162+
))
163+
152164
return return_code
153165

154166

0 commit comments

Comments
 (0)