Skip to content

docs: add integration testing with Testcontainers guide#9363

Open
minitriga wants to merge 6 commits into
stablefrom
docs/testcontainers
Open

docs: add integration testing with Testcontainers guide#9363
minitriga wants to merge 6 commits into
stablefrom
docs/testcontainers

Conversation

@minitriga
Copy link
Copy Markdown
Contributor

@minitriga minitriga commented May 27, 2026

Summary

  • Adds docs/docs/testing-framework/testcontainers.mdx — a how-to guide for the infrahub-testcontainers package covering installation, the TestInfrahubDocker pytest base class and its fixtures, SDK connection setup, environment variable reference, cluster deployment, and a GitHub Actions CI example
  • Converts the Testing Framework sidebar entry from a flat doc to a collapsible category with the new page as a spoke (hub link → overview, spoke → new testcontainers page)
  • Adds Gunicorn, Testcontainers, and testcontainers to .vale/styles/spelling-exceptions.txt

Closes #9362

Reviewer attention

  • Quick-start code example uses infrahubctl schema load (confirmed in tasks/infra_ops.py) and InfrahubClient(config=Config(...)) (confirmed in backend/tests/integration/git/test_git_repository.py). Please verify the Config constructor parameter names match the current SDK version.
  • Token values (INFRAHUB_TESTING_INITIAL_ADMIN_TOKEN) are sourced from python_testcontainers/infrahub_testcontainers/container.py — correct at time of writing but worth a quick check if the package has been updated recently.

Test plan

  • uv run invoke docs.lint — 0 errors (20 pre-existing warnings, none in new file)
  • cd docs && npm run build — build passes
  • Manual: confirm sidebar renders the Testing Framework as a collapsible category with both pages accessible

🤖 Generated with Claude Code


Summary by cubic

Adds a Testcontainers integration testing guide for infrahub-testcontainers, with real-world examples and a debugging workflow. Moves the guide to Development Resources, links it from the Developer Guide, and updates spelling exceptions.

  • New Features
    • Added docs/docs/development-resources/testcontainers.mdx — install, TestInfrahubDockerClient async/sync clients, schema load + wait_until_converged, GitRepo, conftest.py, env vars, cluster mode, CI, debugging with breakpoint() + pytest -s, and real-world examples
    • Linked the page from the Developer Guide and added it to the Development Resources sidebar
    • Updated .vale spelling exceptions (e.g., conftest, Testcontainers, breakpoint, pdb, stdin)

Written for commit 71873b2. Summary will update on new commits. Review in cubic

Adds a how-to guide for `infrahub-testcontainers`, covering installation,
the `TestInfrahubDocker` pytest base class, available fixtures, SDK
connection setup, environment variable reference, cluster deployment, and
CI usage. Converts the testing-framework sidebar entry from a flat doc to
a category so both pages are discoverable. Fixes #9362.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@minitriga minitriga requested review from a team as code owners May 27, 2026 13:33
@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label May 27, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. This PR adds a new documentation page for Testcontainers integration testing, updates spelling exceptions, and restructures the sidebar into a collapsible category—all documentation and configuration changes with no source code impact, so the risk of breaking any functionality is extremely low.

Re-trigger cubic

minitriga and others added 3 commits May 27, 2026 14:41
Replace placeholder examples with patterns sourced from real opsmill
projects (infrahub-demo-service-catalog, devnet-live-2025,
infrahub-solution-ai-dc, infrahub-sdk-python):
- Switch primary class to TestInfrahubDockerClient (from infrahub_sdk.testing.docker)
- Fix auth to username/password (admin/infrahub) instead of token
- Add schema loading pattern using SchemaFile + wait_until_converged
- Add GitRepo repository setup pattern
- Add conftest.py fixture setup (root_dir, schema_dir, data_dir)
- Update fixtures table to include client/client_sync
- Add conftest/Conftest to Vale spelling exceptions

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Links to infrahub-demo-dc, infrahub-demo-service-catalog, and
devnet-live-2025 as public reference implementations.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 3 files (changes from recent commits).

Shadow auto-approve: would auto-approve. The changes are limited to documentation (new testcontainers guide, developer guide update, sidebar restructuring) and adding spelling exceptions, with no modifications to source code, tests, or critical configuration, making the risk of breakage extremely low.

Re-trigger cubic

Covers using breakpoint() + pytest -s to pause test execution and
inspect the live Infrahub instance, plus a fixture override pattern
for keeping containers up after a test failure.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/docs/testing-framework/testcontainers.mdx">

<violation number="1" location="docs/docs/testing-framework/testcontainers.mdx:224">
P2: Wrap `infrahub_compose.start()` with the same try/except error handling as the real fixture, so startup failures during debugging capture and display container logs.</violation>
</file>

Shadow auto-approve: would not auto-approve because issues were found.
Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

```python
@pytest.fixture(scope="class")
def infrahub_app(self, request, infrahub_compose):
infrahub_compose.start()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Wrap infrahub_compose.start() with the same try/except error handling as the real fixture, so startup failures during debugging capture and display container logs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/docs/testing-framework/testcontainers.mdx, line 224:

<comment>Wrap `infrahub_compose.start()` with the same try/except error handling as the real fixture, so startup failures during debugging capture and display container logs.</comment>

<file context>
@@ -176,6 +176,60 @@ pytest tests/ --deployment-type cluster
+```python
+@pytest.fixture(scope="class")
+def infrahub_app(self, request, infrahub_compose):
+    infrahub_compose.start()
+    yield infrahub_compose.get_services_port()
+    # containers are NOT stopped — remember to clean up manually
</file context>
Suggested change
infrahub_compose.start()
try:
infrahub_compose.start()
except Exception as exc:
stdout, stderr = infrahub_compose.get_logs()
raise Exception(f"Failed to start docker compose:\nStdout:\n{stdout}\nStderr:\n{stderr}") from exc

The Testcontainers guide targets external Python developers writing
pytest integration tests against a Dockerized Infrahub — distinct from
the in-repo YAML test framework that runs inside the proposed-change
CI pipeline. Move it next to the Developer Guide so it sits with the
other SDK/CLI-flavored resources, and restore Testing Framework as a
flat doc under Branches & Change Control.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 3 files (changes from recent commits).

Shadow auto-approve: would not auto-approve. Auto-approval blocked by 1 unresolved issue from previous reviews.

Re-trigger cubic

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

Labels

type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task: Add documentation for using Testcontainers with Infrahub

1 participant