From 5295a13105b31d6c9c5fc302f9d8e8ff782dd72f Mon Sep 17 00:00:00 2001 From: Mikhail Yohman Date: Sun, 11 Jan 2026 14:14:57 -0700 Subject: [PATCH] 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 --- infrahub_sdk/pytest_plugin/items/python_transform.py | 1 + infrahub_sdk/pytest_plugin/loader.py | 2 +- infrahub_sdk/pytest_plugin/models.py | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/infrahub_sdk/pytest_plugin/items/python_transform.py b/infrahub_sdk/pytest_plugin/items/python_transform.py index f77b1aa1..0ec42052 100644 --- a/infrahub_sdk/pytest_plugin/items/python_transform.py +++ b/infrahub_sdk/pytest_plugin/items/python_transform.py @@ -89,6 +89,7 @@ def runtest(self) -> None: class InfrahubPythonTransformIntegrationItem(InfrahubPythonTransformItem): def runtest(self) -> None: + self.instantiate_transform() input_data = self.session.infrahub_client.query_gql_query( # type: ignore[attr-defined] self.transform_instance.query, variables=self.test.spec.get_variables_data(), # type: ignore[union-attr] diff --git a/infrahub_sdk/pytest_plugin/loader.py b/infrahub_sdk/pytest_plugin/loader.py index 33040293..8e59fc05 100644 --- a/infrahub_sdk/pytest_plugin/loader.py +++ b/infrahub_sdk/pytest_plugin/loader.py @@ -103,7 +103,7 @@ def collect_group(self, group: InfrahubTestGroup) -> Iterable[Item]: def collect(self) -> Iterable[Item]: raw = yaml.safe_load(self.path.open(encoding="utf-8")) - if "infrahub_tests" not in raw: + if not raw or "infrahub_tests" not in raw: return content = InfrahubTestFileV1(**raw) diff --git a/infrahub_sdk/pytest_plugin/models.py b/infrahub_sdk/pytest_plugin/models.py index 2bebfa77..13e81b90 100644 --- a/infrahub_sdk/pytest_plugin/models.py +++ b/infrahub_sdk/pytest_plugin/models.py @@ -31,7 +31,7 @@ class InfrahubInputOutputTest(InfrahubBaseTest): directory: Path | None = Field( None, description="Path to the directory where the input and output files are located" ) - input: Path = Field( + input: Path | None = Field( Path("input.json"), 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.", ) @@ -68,7 +68,7 @@ def update_paths(self, base_dir: Path) -> None: else: self.directory = base_dir - if not self.input or not self.input.is_file(): + if self.input is not None and not self.input.is_file(): search_input: Path | str = self.input or "input.*" results = list(self.directory.rglob(str(search_input))) @@ -99,6 +99,8 @@ def get_output_data(self) -> Any: class InfrahubIntegrationTest(InfrahubInputOutputTest): + # Integration tests get input from live GraphQL queries, not from input files + input: Path | None = Field(None) variables: Path | dict[str, Any] = Field( Path("variables.json"), description="Variables and corresponding values to pass to the GraphQL query" )