Skip to content

Commit c06bf60

Browse files
ganesh-k13stefanv
andauthored
ENH: Added coverage option for test command (#100)
* ENH: Added coverage option for `test` command * Apply suggestions from code review and also print report to terminal --------- Co-authored-by: Stefan van der Walt <[email protected]>
1 parent ce83f2f commit c06bf60

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

spin/cmds/meson.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,14 @@ def _get_configured_command(command_name):
165165

166166
@click.command()
167167
@click.argument("pytest_args", nargs=-1)
168+
@click.option(
169+
"-c",
170+
"--coverage",
171+
is_flag=True,
172+
help="Generate a coverage report of executed tests. An HTML copy of the report is written to `build/coverage`.",
173+
)
168174
@click.pass_context
169-
def test(ctx, pytest_args):
175+
def test(ctx, pytest_args, coverage=False):
170176
"""🔧 Run tests
171177
172178
PYTEST_ARGS are passed through directly to pytest, e.g.:
@@ -236,6 +242,19 @@ def test(ctx, pytest_args):
236242
print("Stopping. Please investigate the build error.")
237243
sys.exit(1)
238244

245+
if coverage:
246+
coverage_dir = os.path.join(os.getcwd(), "build/coverage/")
247+
if os.path.isdir(coverage_dir):
248+
print(f"Removing `{coverage_dir}`")
249+
shutil.rmtree(coverage_dir)
250+
os.makedirs(coverage_dir)
251+
pytest_args = [
252+
*pytest_args,
253+
"--cov-report=term",
254+
f"--cov-report=html:{coverage_dir}",
255+
f"--cov={package}",
256+
]
257+
239258
print(f'$ export PYTHONPATH="{site_path}"')
240259
_run(
241260
[sys.executable, "-m", "pytest", f"--rootdir={site_path}"] + list(pytest_args),

0 commit comments

Comments
 (0)