File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments