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:
123123 multiple = True ,
124124 help = "Additional argument(s) to pass to pytest. Can be specified multiple times." ,
125125)
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+ )
126132def connector_test (
127133 connector : str | Path | None = None ,
128134 * ,
129135 collect_only : bool = False ,
130136 pytest_args : list [str ] | None = None ,
137+ no_creds : bool = False ,
131138) -> None :
132139 """Run connector tests.
133140
@@ -147,6 +154,9 @@ def connector_test(
147154 if collect_only :
148155 pytest_args .append ("--collect-only" )
149156
157+ if no_creds :
158+ pytest_args .extend (["-m" , "not requires_creds" ])
159+
150160 run_connector_tests (
151161 connector_name = connector_name ,
152162 connector_directory = connector_directory ,
Original file line number Diff line number Diff line change @@ -100,10 +100,17 @@ def build(
100100 "--image" ,
101101 help = "Image to test, instead of building a new one." ,
102102)
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+ )
103109def image_test ( # "image test" command
104110 connector : str | None = None ,
105111 * ,
106112 image : str | None = None ,
113+ no_creds : bool = False ,
107114) -> None :
108115 """Test a connector Docker image.
109116
@@ -124,7 +131,11 @@ def image_test( # "image test" command
124131 connector_name , connector_directory = resolve_connector_name_and_directory (connector )
125132
126133 # 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 ]
128139 if not image :
129140 metadata_file_path : Path = connector_directory / "metadata.yaml"
130141 try :
Original file line number Diff line number Diff line change @@ -186,3 +186,8 @@ def with_expecting_success(self) -> ConnectorTestScenario:
186186 ** self .model_dump (exclude = {"status" }),
187187 status = "succeed" ,
188188 )
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):
161161 if test_class is None :
162162 return
163163
164- # Get the 'scenarios' attribute from the class
164+ # Check that the class is compatible with our test suite
165165 scenarios_attr = getattr (test_class , "get_scenarios" , None )
166166 if scenarios_attr is None :
167167 raise ValueError (
168168 f"Test class { test_class } does not have a 'scenarios' attribute. "
169169 "Please define the 'scenarios' attribute in the test class."
170170 )
171171
172+ # Get the scenarios defined or discovered in the test class
172173 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