Skip to content

Commit 69775f7

Browse files
committed
Added helpful kwargs to 'invoke pytest'
1 parent 23b7cf6 commit 69775f7

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

tasks.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,23 @@ def coverage(context):
169169
run_command(context, "coverage html")
170170

171171

172-
@task
173-
def pytest(context):
172+
@task(
173+
help={
174+
"pattern": "Only run tests which match the given substring. Can be used multiple times.",
175+
"label": "Module path to run (e.g., tests/unit/test_foo.py). Can be used multiple times.",
176+
},
177+
iterable=["pattern", "label"],
178+
)
179+
def pytest(context, pattern=None, label=None):
174180
"""Run pytest test cases."""
175-
exec_cmd = "pytest -vv --doctest-modules netutils/ && coverage run --source=netutils -m pytest && coverage report"
181+
doc_test_cmd = "pytest -vv --doctest-modules netutils/"
182+
pytest_cmd = "coverage run --source=netutils -m pytest"
183+
if pattern:
184+
pytest_cmd += "".join([f" -k {_pattern}" for _pattern in pattern])
185+
if label:
186+
pytest_cmd += "".join([f" {_label}" for _label in label])
187+
coverage_cmd = "coverage report"
188+
exec_cmd = " && ".join([doc_test_cmd, pytest_cmd, coverage_cmd])
176189
run_command(context, exec_cmd)
177190

178191

0 commit comments

Comments
 (0)