Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Added coverage option for test command #100

Merged
merged 2 commits into from
Aug 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion spin/cmds/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,14 @@ def _get_configured_command(command_name):

@click.command()
@click.argument("pytest_args", nargs=-1)
@click.option(
"-c",
"--coverage",
is_flag=True,
help="Generate a coverage report of executed tests. An HTML copy of the report is written to `build/coverage`.",
)
@click.pass_context
def test(ctx, pytest_args):
def test(ctx, pytest_args, coverage=False):
"""🔧 Run tests

PYTEST_ARGS are passed through directly to pytest, e.g.:
Expand Down Expand Up @@ -236,6 +242,19 @@ def test(ctx, pytest_args):
print("Stopping. Please investigate the build error.")
sys.exit(1)

if coverage:
coverage_dir = os.path.join(os.getcwd(), "build/coverage/")
if os.path.isdir(coverage_dir):
print(f"Removing `{coverage_dir}`")
shutil.rmtree(coverage_dir)
os.makedirs(coverage_dir)
pytest_args = [
*pytest_args,
"--cov-report=term",
f"--cov-report=html:{coverage_dir}",
f"--cov={package}",
]

print(f'$ export PYTHONPATH="{site_path}"')
_run(
[sys.executable, "-m", "pytest", f"--rootdir={site_path}"] + list(pytest_args),
Expand Down