ProviderHarness, a mock runtime that lets you test resources without connecting to production infrastructure.
Prerequisites
Your provider project should have pytest configured:ProviderHarness
ProviderHarness simulates the runtime environment, letting you invoke lifecycle methods directly:
LifecycleResult
Each invoke method returns aLifecycleResult with:
| Attribute | Type | Description |
|---|---|---|
success | bool | Whether the lifecycle method succeeded |
failed | bool | Opposite of success (convenience property) |
outputs | Outputs | None | Returned outputs on success |
error | Exception | None | Captured exception on failure |
resource | Resource | The resource instance used |
Testing Create
Testing Update
Pass both the new config and the previous config:Testing Delete
Testing Failures
Verify that your resource rejects invalid configurations:Mocking External Services
Most providers interact with external APIs. Use pytest’smonkeypatch fixture to replace API clients with mocks.
Mock Setup with conftest.py
Create reusable fixtures intests/conftest.py:
Using Mocks in Tests
Mocking GCP Services
For GCP providers, mock the service client and credentials:Testing Idempotency
Verify your lifecycle methods handle retry scenarios correctly.Create Idempotency
Test thaton_create handles “already exists” errors:
Delete Idempotency
Test thaton_delete handles “not found” errors:
Testing Configuration Scenarios
Test different configuration combinations and edge cases.Valid Configurations
Credentials as String or Dict
Some configurations accept credentials as either a dict or JSON string:Tracking Test History
The harness tracks all invocations for debugging:Project Structure
Organize your tests to mirror your resource structure:Sample conftest.py
Running Tests
Run tests with pytest:What’s Next
Lifecycle Methods
Deep dive into on_create, on_update, and on_delete.
SDK Reference
Full SDK documentation.