Test Items and Resource Types
Relevant source files
The following files were used as context for generating this wiki page:
The test items and resource types component provides a structured framework for discovering, loading, and validating Infrahub extensions such as checks and transforms. This framework integrates into standard test suites using a custom pytest plugin architecture to ensure extension code operates properly before integration into the Infrahub pipeline.
Sources: infrahub_sdk/pytest_plugin/loader.py, AGENTS.md
Component Architecture and Discovery Lifecycle
The discovery infrastructure maps local project structures to explicit validation targets. A dedicated directory loader reads target folders, detects file formats, and generates independent test items for each file.
The flowchart above displays how the pytest collection stage invokes the Infrahub directory loader to process target folders and build test execution instances.
Directory Loading
The loading mechanism scans target file system paths to discover extensions. It analyzes file names and file properties to construct test items.
Sources: infrahub_sdk/pytest_plugin/loader.py, infrahub_sdk/pytest_plugin/items/base.py
| Component | Target Artifact | Discoverable Subdirectory / Pattern |
|---|---|---|
InfrahubCheckItem | Code validations and structural constraints | Files under directories designated for data validation |
InfrahubPythonTransformItem | Data mutations and structural mappings | Files under directories designated for data translation |
Sources: infrahub_sdk/pytest_plugin/loader.py, infrahub_sdk/pytest_plugin/items/check.py, infrahub_sdk/pytest_plugin/items/python_transform.py
Test Item Core Specification
Every validation target subclasses a base test execution element. The base class provides logging, problem reporting, and standard pytest reporting overrides.
The class diagram above displays the inheritance hierarchy from standard pytest execution components to specialized Infrahub test verification types.
Failure Representation and Reporting
The item base class intercepts runtime faults to format terminal diagnostics. It replaces standard stack traces with contextual parameters extracted directly from the runtime environment.
Sources: infrahub_sdk/pytest_plugin/items/base.py
Specialized Resource Types
Infrahub Check Items
The check execution item processes validations that guarantee structural integrity. It discovers validation targets, checks input boundaries, and tracks generated compliance exceptions.
Sources: infrahub_sdk/pytest_plugin/items/check.py
Infrahub Python Transform Items
The transform execution item verifies data translation logic. It exercises transformation code to ensure it processes input topologies and returns expected mutations.
Sources: infrahub_sdk/pytest_plugin/items/python_transform.py
Development Constraints and Tooling
Code artifacts within this ecosystem must comply with the foundational quality gates specified by the SDK engineering configuration.
- Format and Style Boundaries: Code must successfully execute formatting via
ruff formatand validation usingruff check. - Static Typing Contracts: Public signatures must specify unambiguous type annotations that satisfy both
tyandmypyverifications. - Markdown Documentation Hygiene: Unordered lists must have explicit leading and trailing blank lines, and all code blocks must identify the target format language.
Sources: AGENTS.md, infrahub_sdk/pytest_plugin/AGENTS.md
Summary
The test items and resource types components establish a reliable framework for testing Infrahub extensions. By converting local check and transform scripts into standard pytest elements, the system validates extension behavior before it enters production environments.