Skip to content

Conversation

@FragmentedPacket
Copy link
Contributor

@FragmentedPacket FragmentedPacket commented Jan 11, 2026

  • 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

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Resolved initialization order issue in integration tests to ensure proper setup before query execution.
    • Strengthened test data validation to gracefully handle missing or empty test data, preventing unexpected errors.
  • New Features

    • Extended test framework to support test scenarios without requiring input files, offering greater flexibility.

✏️ Tip: You can customize this high-level summary in your review settings.

- 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
@coderabbitai
Copy link

coderabbitai bot commented Jan 11, 2026

Walkthrough

The changes modify the pytest plugin for Infrahub across three files. The transform integration item now calls self.instantiate_transform() before performing GraphQL queries. The loader condition is updated to verify that raw data is truthy in addition to checking for the "infrahub_tests" key presence. The models update the input field type to Path | None in InfrahubInputOutputTest and add an input field override in InfrahubIntegrationTest with a default value of None.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main changes: fixing the pytest plugin to handle integration tests and empty YAML files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5295a13
Status: ✅  Deploy successful!
Preview URL: https://4af976ec.infrahub-sdk-python.pages.dev
Branch Preview URL: https://may-202601-pytest-plugin-upd.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Jan 11, 2026

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...frahub_sdk/pytest_plugin/items/python_transform.py 0.00% 1 Missing ⚠️
infrahub_sdk/pytest_plugin/loader.py 0.00% 0 Missing and 1 partial ⚠️
infrahub_sdk/pytest_plugin/models.py 66.66% 0 Missing and 1 partial ⚠️
@@            Coverage Diff             @@
##           stable     #744      +/-   ##
==========================================
- Coverage   80.30%   80.29%   -0.01%     
==========================================
  Files         115      115              
  Lines        9874     9876       +2     
  Branches     1518     1518              
==========================================
+ Hits         7929     7930       +1     
- Misses       1417     1418       +1     
  Partials      528      528              
Flag Coverage Δ
integration-tests 41.29% <0.00%> (-0.01%) ⬇️
python-3.10 50.92% <0.00%> (-0.02%) ⬇️
python-3.11 50.92% <0.00%> (-0.02%) ⬇️
python-3.12 50.88% <0.00%> (-0.04%) ⬇️
python-3.13 50.90% <0.00%> (+<0.01%) ⬆️
python-3.14 52.54% <0.00%> (+<0.01%) ⬆️
python-filler-3.12 24.03% <40.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...frahub_sdk/pytest_plugin/items/python_transform.py 60.37% <0.00%> (-1.17%) ⬇️
infrahub_sdk/pytest_plugin/loader.py 75.51% <0.00%> (ø)
infrahub_sdk/pytest_plugin/models.py 79.09% <66.66%> (+0.19%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
infrahub_sdk/pytest_plugin/items/python_transform.py (1)

90-99: Avoid double-instantiation in integration runs (instantiate now happens twice).

With the new self.instantiate_transform() on Line 92 and the existing run_transform() behavior, integration tests will create two transform instances per test. Consider caching / “ensure instantiated” so the pre-query instantiation is reused for the actual run.

One approach (initialize + guard)
 class InfrahubPythonTransformItem(InfrahubItem):
@@
     ) -> None:
         super().__init__(*args, resource_name=resource_name, resource_config=resource_config, test=test, **kwargs)
 
-        self.transform_instance: InfrahubTransform
+        self.transform_instance: InfrahubTransform | None = None
 
     def instantiate_transform(self) -> None:
+        if self.transform_instance is not None:
+            return
         relative_path = (
             str(self.resource_config.file_path.parent) if self.resource_config.file_path.parent != Path() else None  # type: ignore[attr-defined]
         )
@@
         self.transform_instance = transform_class(branch="", client=client, infrahub_node=InfrahubNode)
 
     def run_transform(self, variables: dict[str, Any]) -> Any:
         self.instantiate_transform()
-        return asyncio.run(self.transform_instance.run(data=variables))
+        assert self.transform_instance is not None
+        return asyncio.run(self.transform_instance.run(data=variables))
infrahub_sdk/pytest_plugin/models.py (1)

30-41: Align input field semantics: either make it required (Path type with default) or truly optional (Path | None with None default).

The current signature input: Path | None = Field(Path("input.json")) is semantically contradictory—the optional type hint conflicts with the non-None default. The implementation does handle None correctly (with fallback pattern matching via search_input: Path | str = self.input or "input.*"), but InfrahubIntegrationTest uses the pattern input: Path | None = Field(None), suggesting the base class should align. Either change the base class default to None (matching the optional type and subclass pattern) or remove the None type and commit to a required input with default discovery behavior.

🧹 Nitpick comments (1)
infrahub_sdk/pytest_plugin/models.py (1)

63-82: Remove now-unreachable "input.*" fallback (or rework discovery logic if you intended it).

Because of if self.input is not None ..., search_input = self.input or "input.*" will never use "input.*". If this is just legacy residue, simplify; if you intended wildcard discovery when input is unset, the control-flow needs adjusting.

Proposed minimal cleanup
-        if self.input is not None and not self.input.is_file():
-            search_input: Path | str = self.input or "input.*"
+        if self.input is not None and not self.input.is_file():
+            search_input: Path | str = self.input
             results = list(self.directory.rglob(str(search_input)))
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d116aa3 and 5295a13.

📒 Files selected for processing (3)
  • infrahub_sdk/pytest_plugin/items/python_transform.py
  • infrahub_sdk/pytest_plugin/loader.py
  • infrahub_sdk/pytest_plugin/models.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Use type hints on all function signatures
Never mix async/sync inappropriately
Never bypass type checking without justification

Files:

  • infrahub_sdk/pytest_plugin/items/python_transform.py
  • infrahub_sdk/pytest_plugin/loader.py
  • infrahub_sdk/pytest_plugin/models.py
infrahub_sdk/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Follow async/sync dual pattern for new features in the Python SDK

Files:

  • infrahub_sdk/pytest_plugin/items/python_transform.py
  • infrahub_sdk/pytest_plugin/loader.py
  • infrahub_sdk/pytest_plugin/models.py
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: infrahub_sdk/pytest_plugin/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:29.593Z
Learning: Applies to infrahub_sdk/pytest_plugin/**/*.yaml : Use YAML test format with required fields: `infrahub_tests`, `resource`, `resource_name`, `tests` array containing `name`, `spec.kind`, `input`, and `output`
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: infrahub_sdk/pytest_plugin/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:29.593Z
Learning: Applies to infrahub_sdk/pytest_plugin/**/infrahub_sdk/pytest_plugin/loader.py : Register new test items in `ITEMS_MAPPING` in `infrahub_sdk/pytest_plugin/loader.py`
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: infrahub_sdk/pytest_plugin/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:29.593Z
Learning: Applies to infrahub_sdk/pytest_plugin/**/infrahub_sdk/pytest_plugin/items/*.py : Inherit from `InfrahubItem` base class when creating new test item classes in `infrahub_sdk/pytest_plugin/items/`
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: tests/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:37.990Z
Learning: Applies to tests/integration/**/*.py : Integration tests should use testcontainers to interact with real Infrahub instances
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: infrahub_sdk/pytest_plugin/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:29.593Z
Learning: Applies to infrahub_sdk/pytest_plugin/**/*.yaml : Define test `kind` values according to resource type and test level (smoke, unit, integration) as specified in the test kinds table
📚 Learning: 2025-12-10T17:13:29.593Z
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: infrahub_sdk/pytest_plugin/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:29.593Z
Learning: Applies to infrahub_sdk/pytest_plugin/**/infrahub_sdk/pytest_plugin/items/*.py : Inherit from `InfrahubItem` base class when creating new test item classes in `infrahub_sdk/pytest_plugin/items/`

Applied to files:

  • infrahub_sdk/pytest_plugin/items/python_transform.py
  • infrahub_sdk/pytest_plugin/loader.py
  • infrahub_sdk/pytest_plugin/models.py
📚 Learning: 2025-12-10T17:13:29.593Z
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: infrahub_sdk/pytest_plugin/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:29.593Z
Learning: Applies to infrahub_sdk/pytest_plugin/**/infrahub_sdk/pytest_plugin/loader.py : Register new test items in `ITEMS_MAPPING` in `infrahub_sdk/pytest_plugin/loader.py`

Applied to files:

  • infrahub_sdk/pytest_plugin/items/python_transform.py
  • infrahub_sdk/pytest_plugin/loader.py
📚 Learning: 2025-12-10T17:13:37.990Z
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: tests/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:37.990Z
Learning: Applies to tests/integration/**/*.py : Integration tests should use testcontainers to interact with real Infrahub instances

Applied to files:

  • infrahub_sdk/pytest_plugin/items/python_transform.py
  • infrahub_sdk/pytest_plugin/models.py
📚 Learning: 2025-12-10T17:13:29.593Z
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: infrahub_sdk/pytest_plugin/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:29.593Z
Learning: Applies to infrahub_sdk/pytest_plugin/**/*.yaml : Use YAML test format with required fields: `infrahub_tests`, `resource`, `resource_name`, `tests` array containing `name`, `spec.kind`, `input`, and `output`

Applied to files:

  • infrahub_sdk/pytest_plugin/loader.py
  • infrahub_sdk/pytest_plugin/models.py
📚 Learning: 2025-12-10T17:13:29.593Z
Learnt from: CR
Repo: opsmill/infrahub-sdk-python PR: 0
File: infrahub_sdk/pytest_plugin/AGENTS.md:0-0
Timestamp: 2025-12-10T17:13:29.593Z
Learning: Applies to infrahub_sdk/pytest_plugin/**/*.yaml : Define test `kind` values according to resource type and test level (smoke, unit, integration) as specified in the test kinds table

Applied to files:

  • infrahub_sdk/pytest_plugin/models.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: unit-tests (3.14)
  • GitHub Check: unit-tests (3.10)
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: unit-tests (3.11)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
infrahub_sdk/pytest_plugin/models.py (1)

101-107: LGTM: integration tests default input=None matches “input comes from live GraphQL”.

The override makes InfrahubIntegrationTest skip input file resolution (since update_paths() now guards self.input is not None).

infrahub_sdk/pytest_plugin/loader.py (1)

103-110: LGTM: empty YAML now safely produces no collected items.

if not raw ...: return avoids constructing InfrahubTestFileV1(**raw) when yaml.safe_load() returns None (common for empty files).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants