3
3
#
4
4
5
5
import logging
6
+ from pathlib import Path
7
+ from typing import List
6
8
7
9
import asyncclick as click
8
10
from pipelines .cli .click_decorators import click_ignore_unused_kwargs , click_merge_args_into_context_obj
13
15
14
16
@click .command ()
15
17
@click .argument ("poetry_package_path" )
16
- @click .option ("--test-directory" , default = "tests" , help = "The directory containing the tests to run." )
18
+ @click .option (
19
+ "-c" ,
20
+ "--poetry-run-command" ,
21
+ multiple = True ,
22
+ help = "The poetry run command to run." ,
23
+ required = True ,
24
+ )
17
25
@click_merge_args_into_context_obj
18
26
@pass_pipeline_context
19
27
@click_ignore_unused_kwargs
@@ -24,7 +32,10 @@ async def test(pipeline_context: ClickPipelineContext):
24
32
pipeline_context (ClickPipelineContext): The context object.
25
33
"""
26
34
poetry_package_path = pipeline_context .params ["poetry_package_path" ]
27
- test_directory = pipeline_context .params ["test_directory" ]
35
+ if not Path (f"{ poetry_package_path } /pyproject.toml" ).exists ():
36
+ raise click .UsageError (f"Could not find pyproject.toml in { poetry_package_path } " )
37
+
38
+ commands_to_run : List [str ] = pipeline_context .params ["poetry_run_command" ]
28
39
29
40
logger = logging .getLogger (f"{ poetry_package_path } .tests" )
30
41
logger .info (f"Running tests for { poetry_package_path } " )
@@ -47,7 +58,7 @@ async def test(pipeline_context: ClickPipelineContext):
47
58
48
59
pipeline_name = f"Unit tests for { poetry_package_path } "
49
60
dagger_client = await pipeline_context .get_dagger_client (pipeline_name = pipeline_name )
50
- pytest_container = await (
61
+ test_container = await (
51
62
dagger_client .container ()
52
63
.from_ ("python:3.10.12" )
53
64
.with_env_variable ("PIPX_BIN_DIR" , "/usr/local/bin" )
@@ -73,10 +84,11 @@ async def test(pipeline_context: ClickPipelineContext):
73
84
),
74
85
)
75
86
.with_workdir (f"/airbyte/{ poetry_package_path } " )
76
- .with_exec (["poetry" , "install" ])
87
+ .with_exec (["poetry" , "install" , "--with=dev" ])
77
88
.with_unix_socket ("/var/run/docker.sock" , dagger_client .host ().unix_socket ("/var/run/docker.sock" ))
78
89
.with_env_variable ("CI" , str (pipeline_context .params ["is_ci" ]))
79
- .with_exec ([ "poetry" , "run" , "pytest" , test_directory ] )
90
+ .with_workdir ( f"/airbyte/ { poetry_package_path } " )
80
91
)
81
-
82
- await pytest_container
92
+ for command in commands_to_run :
93
+ test_container = test_container .with_exec (["poetry" , "run" , * command .split (" " )])
94
+ await test_container
0 commit comments