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
|
from invoke import task
from .utils import ctx_run
@task(
help={
"coverage": "Build and report on test coverage",
"test-pattern": "Pattern used to select test files to run",
"update-snapshots": "Create, update or delete snapshot files",
"verbose": "Verbose output e.g. non captured logs etc.",
}
)
def test(
ctx,
coverage=False,
test_pattern=None,
update_snapshots=False,
verbose=False,
debug=False,
):
"""
Run entire test suite
"""
flags = {
"-s -vv": verbose,
f"-k {test_pattern}": test_pattern,
"--snapshot-update": update_snapshots,
}
coverage_module = "coverage run -m " if coverage else ""
test_flags = " ".join(flag for flag, enabled in flags.items() if enabled)
if debug and coverage:
raise Exception("The debug and coverage options are mutually exclusive.")
if debug:
ctx_run(
ctx,
f"python -m debugpy --listen 5678 --wait-for-client -m pytest {test_flags} ./tests",
)
else:
ctx_run(ctx, f"python -m {coverage_module}pytest {test_flags} ./tests")
if coverage:
ctx_run(ctx, "coverage lcov -o coverage/coverage.lcov")
|