Bicep Testing Framework for Python
Test the resources, outputs, and diagnostics produced by a Bicep deployment without deploying to Azure. The package can also run opt-in integration tests against a real Azure Deployment Stack when an assertion requires live resources.
This is an independent, non-official project.
Requirements
- Python 3.11 or later
- A
.bicepparamentry point for the deployment under test
Installation
python -m pip install anthonycmartin-bicep-testing==0.1.7
Snapshot testing
Use BicepTestSession as a context manager so its Bicep process is always closed:
from anthonycmartin.bicep_testing import BicepTestSession
with BicepTestSession.create("0.46.1") as session:
snapshot = session.snapshot("infra/main.bicepparam")
storage_accounts = [
resource
for resource in snapshot.predicted_resources
if resource.type == "Microsoft.Storage/storageAccounts"
]
assert snapshot.diagnostics == ()
assert storage_accounts
assert all(
resource.properties["allowBlobPublicAccess"] is False
for resource in storage_accounts
)
BicepTestSession.create() downloads the requested Bicep CLI version into ~/.bicep/bin and reuses it on later runs. The session owns a Bicep process, so use it as a context manager or call close() after the tests finish.
Snapshot tests run locally. The subscription, tenant, resource group, location, and deployment values provide evaluation context only; they do not need to exist, and no Azure credentials are required.
Metadata is optional. Supply it when assertions depend on those values.
deployment_name also affects offline deployment().name evaluation.
Management-group context and helpers (unreleased)
The development checkout adds SnapshotMetadata.management_group_id, requiring
Bicep CLI 0.47.16+. Older CLIs raise RuntimeError.
from anthonycmartin.bicep_testing import (
BicepTestSession, SnapshotMetadata, resources_of_type, require_resource,
get_resource_scope, get_snapshot_value,
)
with BicepTestSession.create("0.47.16") as session:
snapshot = session.snapshot("infra/management-group.bicepparam", SnapshotMetadata(
management_group_id="example-platform", location="eastus", deployment_name="offline-test",
))
assert snapshot.diagnostics == ()
assert len(resources_of_type(snapshot, "Microsoft.Authorization/policyDefinitions")) == 1
policy = require_resource(snapshot, type="Microsoft.Authorization/policyDefinitions", name="require-cost-center")
assert get_resource_scope(policy.id).management_group_id == "example-platform"
assert get_snapshot_value(policy.properties, "/policyRule/then/effect") == "audit"
Use the shared management-group fixture.
require_resource(snapshot, id=resource_id) is the alternative selector.
Types and IDs match case-insensitively; names match exactly. Type selection
returns an empty tuple when absent; required selection raises ValueError for
zero or multiple matches, mixed selectors, or empty arguments.
get_resource_scope() returns a frozen ResourceScope with None for absent
subscription/resource-group/management-group components. It supports tenant,
child, and extension IDs, raises ValueError for malformed IDs, and requires GUID
subscription IDs. Tenant IDs cannot be inferred from resource IDs.
get_snapshot_value() accepts decoded JSON mappings/lists and an RFC 6901 JSON
Pointer: "" returns the input, /items/0 indexes an array, and ~0/~1 escape
~//. It preserves explicit None, raises KeyError for missing paths and
noncanonical indices, and raises ValueError for invalid syntax. Raw mappings
and resource models remain available.
BicepTestSession is intentionally offline-only. Use LiveBicepTestSession for Azure validation and deployment.
Snapshot results
snapshot() returns an immutable SnapshotResult containing:
predicted_resources: resources and resolved properties predicted for the deploymentoutputs: resolved deployment outputsdiagnostics: Bicep compilation warnings and errors
Each resource exposes its name, type, API version, location, properties, and additional fields returned by Bicep.
Live deployment testing
Use LiveBicepTestSession when a test must inspect real Azure resources or service responses. The live session owns the credential and forwards snapshot operations:
from azure.identity import DefaultAzureCredential
from anthonycmartin.bicep_testing import (
LiveBicepTestSession,
ResourceGroupDeployOptions,
)
with LiveBicepTestSession.create("0.46.1", DefaultAzureCredential()) as session:
validation = session.validate(
ResourceGroupDeployOptions(
file_path="infra/main.bicepparam",
subscription_id=subscription_id,
resource_group=resource_group,
)
)
assert validation.is_valid
with session.deploy(
ResourceGroupDeployOptions(
file_path="infra/main.bicepparam",
subscription_id=subscription_id,
resource_group=resource_group,
parameter_overrides={"env": "integration"},
)
) as deployment:
assert deployment.succeeded
assert any(
resource.type == "Microsoft.Storage/storageAccounts"
for resource in deployment.resources
)
Live tests require Azure credentials and permission to create and delete Deployment Stacks and their managed resources.
Deployment options are immutable dataclasses:
ResourceGroupDeployOptions(file_path, subscription_id, resource_group, location=None, stack_name=..., parameter_overrides=...)SubscriptionDeployOptions(file_path, subscription_id, location, stack_name=..., parameter_overrides=...)ManagementGroupDeployOptions(file_path, management_group_id, location, stack_name=..., parameter_overrides=...)
stack_name defaults to bicep-test-<32 lowercase hex characters>.
validate() returns immutable ValidateResult with:
is_validresourcescorrelation_iderror(OperationErrorwithcode,message,raw_data)
deploy() returns immutable DeployResult for both success and post-submission Azure failures, with:
succeedederror,error_code,error_messageoutputsresources
DeployResult is a context manager and supports idempotent teardown via close(). A 404 during deletion is treated as already removed.
Lower-level Bicep integrations can use the separately distributed anthonycmartin-bicep-rpc-client.
More information
The live samples include opt-in
identical redeployment with cleanup after both operations. Reuse the options
instance or explicitly supply the same stack_name.
Copy the consumer authoring skill
into your repository for AI-generated tests. Automated scenario coverage is not
yet available.
Metadata
Release files for anthonycmartin-bicep-testing 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| anthonycmartin_bicep_testing-0.1.7.tar.gz | 18.2 kB | With provenance | Details for anthonycmartin_bicep_testing-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anthonycmartin_bicep_testing-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for anthonycmartin_bicep_testing-0.1.7-py3-none-any.whl |
Total release size: 31.1 kB
Release files / anthonycmartin_bicep_testing-0.1.7.tar.gz
| Download URL | anthonycmartin_bicep_testing-0.1.7.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0dfc6df46a5e1ac058c05016036317722db3285f39cb7bf0bd6e15acae8d5ef6
|
|
BLAKE2b-256 checksum How to use checksums |
d7b3ba1156fd97dd443c66430784d2f655e422bcee255bd2992e4214fa0b38ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.
Transparency logRelease files / anthonycmartin_bicep_testing-0.1.7-py3-none-any.whl
| Download URL | anthonycmartin_bicep_testing-0.1.7-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6fe62f1080a194744661f31d9343d9e3c2f53d22e5ad16b66274ddf11ad220d7
|
|
BLAKE2b-256 checksum How to use checksums |
80a08733024fe98de6e699cfcf4d3b5d102903170417381f2667c5067e5f6ff1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.
Transparency logSecurity for anthonycmartin-bicep-testing 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for anthonycmartin_bicep_testing-0.1.7.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.