Skip to content

Commit 5295a13

Browse files
Fix pytest plugin for integration tests and empty YAML files
- Add missing instantiate_transform() call in integration test runner - Handle empty YAML files gracefully in loader to avoid TypeError - Make input field optional in InfrahubInputOutputTest model - Default input to None for InfrahubIntegrationTest since integration tests get input from live GraphQL queries, not files
1 parent d116aa3 commit 5295a13

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

infrahub_sdk/pytest_plugin/items/python_transform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def runtest(self) -> None:
8989

9090
class InfrahubPythonTransformIntegrationItem(InfrahubPythonTransformItem):
9191
def runtest(self) -> None:
92+
self.instantiate_transform()
9293
input_data = self.session.infrahub_client.query_gql_query( # type: ignore[attr-defined]
9394
self.transform_instance.query,
9495
variables=self.test.spec.get_variables_data(), # type: ignore[union-attr]

infrahub_sdk/pytest_plugin/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def collect_group(self, group: InfrahubTestGroup) -> Iterable[Item]:
103103
def collect(self) -> Iterable[Item]:
104104
raw = yaml.safe_load(self.path.open(encoding="utf-8"))
105105

106-
if "infrahub_tests" not in raw:
106+
if not raw or "infrahub_tests" not in raw:
107107
return
108108

109109
content = InfrahubTestFileV1(**raw)

infrahub_sdk/pytest_plugin/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class InfrahubInputOutputTest(InfrahubBaseTest):
3131
directory: Path | None = Field(
3232
None, description="Path to the directory where the input and output files are located"
3333
)
34-
input: Path = Field(
34+
input: Path | None = Field(
3535
Path("input.json"),
3636
description="Path to the file with the input data for the test, can be a relative path from the config file or from the directory.",
3737
)
@@ -68,7 +68,7 @@ def update_paths(self, base_dir: Path) -> None:
6868
else:
6969
self.directory = base_dir
7070

71-
if not self.input or not self.input.is_file():
71+
if self.input is not None and not self.input.is_file():
7272
search_input: Path | str = self.input or "input.*"
7373
results = list(self.directory.rglob(str(search_input)))
7474

@@ -99,6 +99,8 @@ def get_output_data(self) -> Any:
9999

100100

101101
class InfrahubIntegrationTest(InfrahubInputOutputTest):
102+
# Integration tests get input from live GraphQL queries, not from input files
103+
input: Path | None = Field(None)
102104
variables: Path | dict[str, Any] = Field(
103105
Path("variables.json"), description="Variables and corresponding values to pass to the GraphQL query"
104106
)

0 commit comments

Comments
 (0)