@@ -39,7 +39,7 @@ def is_truthy(arg):
3939 "python_ver" : "3.10" ,
4040 "local" : is_truthy (os .getenv ("INVOKE_DIFFSYNC_LOCAL" , "false" )),
4141 "image_name" : "diffsync" ,
42- "image_ver" : os .getenv ("INVOKE_PARSER_IMAGE_VER " , "latest" ),
42+ "image_ver" : os .getenv ("INVOKE_DIFFSYNC_IMAGE_VER " , "latest" ),
4343 "pwd" : Path (__file__ ).parent ,
4444 }
4545 }
@@ -66,13 +66,14 @@ def task_wrapper(function=None):
6666 return task_wrapper
6767
6868
69- def run_command (context , exec_cmd , port = None ):
69+ def run_command (context , exec_cmd , port = None , rm = True ):
7070 """Wrapper to run the invoke task commands.
7171
7272 Args:
7373 context ([invoke.task]): Invoke task object.
7474 exec_cmd ([str]): Command to run.
7575 port (int): Used to serve local docs.
76+ rm (bool): Whether to remove the container after running the command.
7677
7778 Returns:
7879 result (obj): Contains Invoke result from running task.
@@ -86,12 +87,12 @@ def run_command(context, exec_cmd, port=None):
8687 )
8788 if port :
8889 result = context .run (
89- f"docker run -it -p { port } -v { context .diffsync .pwd } :/local { context .diffsync .image_name } :{ context .diffsync .image_ver } sh -c '{ exec_cmd } '" ,
90+ f"docker run -it { '--rm' if rm else '' } -p { port } -v { context .diffsync .pwd } :/local { context .diffsync .image_name } :{ context .diffsync .image_ver } sh -c '{ exec_cmd } '" ,
9091 pty = True ,
9192 )
9293 else :
9394 result = context .run (
94- f"docker run -it -v { context .diffsync .pwd } :/local { context .diffsync .image_name } :{ context .diffsync .image_ver } sh -c '{ exec_cmd } '" ,
95+ f"docker run -it { '--rm' if rm else '' } -v { context .diffsync .pwd } :/local { context .diffsync .image_name } :{ context .diffsync .image_ver } sh -c '{ exec_cmd } '" ,
9596 pty = True ,
9697 )
9798
@@ -169,12 +170,28 @@ def coverage(context):
169170 run_command (context , "coverage html" )
170171
171172
172- @task
173- def pytest (context ):
173+ @task (
174+ help = {
175+ "pattern" : "Only run tests which match the given substring. Can be used multiple times." ,
176+ "label" : "Module path to run (e.g., tests/unit/test_foo.py). Can be used multiple times." ,
177+ },
178+ iterable = ["pattern" , "label" ],
179+ )
180+ def pytest (context , pattern = None , label = None ):
174181 """Run pytest test cases."""
175182 exec_cmd = "pytest -vv --doctest-modules diffsync/ && coverage run --source=diffsync -m pytest && coverage report"
176183 run_command (context , exec_cmd )
177184
185+ doc_test_cmd = "pytest -vv --doctest-modules diffsync/"
186+ pytest_cmd = "coverage run --source=diffsync -m pytest"
187+ if pattern :
188+ pytest_cmd += "" .join ([f" -k { _pattern } " for _pattern in pattern ])
189+ if label :
190+ pytest_cmd += "" .join ([f" { _label } " for _label in label ])
191+ coverage_cmd = "coverage report"
192+ exec_cmd = " && " .join ([doc_test_cmd , pytest_cmd , coverage_cmd ])
193+ run_command (context , exec_cmd )
194+
178195
179196@task (aliases = ("a" ,))
180197def autoformat (context ):
0 commit comments