Skip to content

Commit 23ee94b

Browse files
committed
add dynamic 'requires_creds' marks
1 parent e3aa52e commit 23ee94b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

airbyte_cdk/test/models/scenario.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

airbyte_cdk/test/standard_tests/pytest_hooks.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff 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+
)

0 commit comments

Comments
 (0)