File tree Expand file tree Collapse file tree 4 files changed +45
-4
lines changed Expand file tree Collapse file tree 4 files changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -123,11 +123,18 @@ def connector_cli_group() -> None:
123
123
multiple = True ,
124
124
help = "Additional argument(s) to pass to pytest. Can be specified multiple times." ,
125
125
)
126
+ @click .option (
127
+ "--no-creds" ,
128
+ is_flag = True ,
129
+ default = False ,
130
+ help = "Skip tests that require credentials (marked with 'requires_creds')." ,
131
+ )
126
132
def connector_test (
127
133
connector : str | Path | None = None ,
128
134
* ,
129
135
collect_only : bool = False ,
130
136
pytest_args : list [str ] | None = None ,
137
+ no_creds : bool = False ,
131
138
) -> None :
132
139
"""Run connector tests.
133
140
@@ -147,6 +154,9 @@ def connector_test(
147
154
if collect_only :
148
155
pytest_args .append ("--collect-only" )
149
156
157
+ if no_creds :
158
+ pytest_args .extend (["-m" , "not requires_creds" ])
159
+
150
160
run_connector_tests (
151
161
connector_name = connector_name ,
152
162
connector_directory = connector_directory ,
Original file line number Diff line number Diff line change @@ -100,10 +100,17 @@ def build(
100
100
"--image" ,
101
101
help = "Image to test, instead of building a new one." ,
102
102
)
103
+ @click .option (
104
+ "--no-creds" ,
105
+ is_flag = True ,
106
+ default = False ,
107
+ help = "Skip tests that require credentials (marked with 'requires_creds')." ,
108
+ )
103
109
def image_test ( # "image test" command
104
110
connector : str | None = None ,
105
111
* ,
106
112
image : str | None = None ,
113
+ no_creds : bool = False ,
107
114
) -> None :
108
115
"""Test a connector Docker image.
109
116
@@ -124,7 +131,11 @@ def image_test( # "image test" command
124
131
connector_name , connector_directory = resolve_connector_name_and_directory (connector )
125
132
126
133
# Select only tests with the 'image_tests' mark
127
- pytest_args = ["-m" , "image_tests" ]
134
+ pytest_filter = "image_tests"
135
+ if no_creds :
136
+ pytest_filter += " and not requires_creds"
137
+
138
+ pytest_args = ["-m" , pytest_filter ]
128
139
if not image :
129
140
metadata_file_path : Path = connector_directory / "metadata.yaml"
130
141
try :
Original file line number Diff line number Diff line change @@ -186,3 +186,8 @@ def with_expecting_success(self) -> ConnectorTestScenario:
186
186
** self .model_dump (exclude = {"status" }),
187
187
status = "succeed" ,
188
188
)
189
+
190
+ @property
191
+ def requires_creds (self ) -> bool :
192
+ """Return True if the scenario requires credentials to run."""
193
+ return bool (self .config_path and "secrets" in self .config_path .parts )
Original file line number Diff line number Diff line change @@ -161,14 +161,29 @@ class TestMyConnector(ConnectorTestSuiteBase):
161
161
if test_class is None :
162
162
return
163
163
164
- # Get the 'scenarios' attribute from the class
164
+ # Check that the class is compatible with our test suite
165
165
scenarios_attr = getattr (test_class , "get_scenarios" , None )
166
166
if scenarios_attr is None :
167
167
raise ValueError (
168
168
f"Test class { test_class } does not have a 'scenarios' attribute. "
169
169
"Please define the 'scenarios' attribute in the test class."
170
170
)
171
171
172
+ # Get the scenarios defined or discovered in the test class
172
173
scenarios = test_class .get_scenarios ()
173
- ids = [str (scenario ) for scenario in scenarios ]
174
- metafunc .parametrize ("scenario" , scenarios , ids = ids )
174
+
175
+ # Create pytest.param objects with special marks as needed
176
+ parametrized_scenarios = [
177
+ pytest .param (
178
+ scenario ,
179
+ marks = [pytest .mark .requires_creds ] if scenario .requires_creds else [],
180
+ )
181
+ for scenario in scenarios
182
+ ]
183
+
184
+ # Parametrize the 'scenario' argument with the scenarios
185
+ metafunc .parametrize (
186
+ "scenario" ,
187
+ parametrized_scenarios ,
188
+ ids = [str (scenario ) for scenario in scenarios ],
189
+ )
You can’t perform that action at this time.
0 commit comments