Bicep Testing 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.2
Snapshot testing
Use BicepTestSession as a context manager so its Bicep process is always closed:
from anthonycmartin.bicep_testing import BicepTestSession, SnapshotMetadata
metadata = SnapshotMetadata(
tenant_id="00000000-0000-0000-0000-000000000000",
subscription_id="00000000-0000-0000-0000-000000000000",
resource_group="example-rg",
location="eastus",
deployment_name="example-deployment",
)
with BicepTestSession.create("0.43.1") as session:
snapshot = session.snapshot("infra/main.bicepparam", metadata)
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.
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 deploy() only when a test must inspect a real Azure resource or service response. The result is also a context manager, so teardown runs when an assertion fails:
import uuid
from azure.identity import DefaultAzureCredential
with session.deploy(
DefaultAzureCredential(),
"infra/main.bicepparam",
subscription_id,
resource_group,
f"bicep-test-{uuid.uuid4().hex}",
{"env": "integration"},
) as deployment:
assert any(
resource.type == "Microsoft.Storage/storageAccounts"
for resource in deployment.resources
)
Live tests require Azure credentials, an existing resource group, and permission to create and delete Deployment Stacks and their managed resources. Closing the result is idempotent and deletes the stack and all resources it manages. Use a unique stack name and keep the result in a context manager.
Lower-level Bicep integrations can use the separately distributed anthonycmartin-bicep-rpc-client.
More information
Metadata
Release files for anthonycmartin-bicep-testing 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| anthonycmartin_bicep_testing-0.1.2.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| anthonycmartin_bicep_testing-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / anthonycmartin_bicep_testing-0.1.2.tar.gz
| Download URL | anthonycmartin_bicep_testing-0.1.2.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a62797384ae6913c7cb51b63b99efd867335cfa2684b9a0f2fcd53c020abe92
|
|
BLAKE2b-256 checksum How to use checksums |
f6d67ae5edd2c30ba5f27f514757ea3bc35e172b7b83e4b56d1de2219a384333
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 9, 2026.
Transparency logRelease files / anthonycmartin_bicep_testing-0.1.2-py3-none-any.whl
| Download URL | anthonycmartin_bicep_testing-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a435ad9a8d733ead3ba8b653baf3483b94b117ccc35174fc837f3724ec42a29
|
|
BLAKE2b-256 checksum How to use checksums |
72bc0616cf9c4bc458c22f39f9da1acee7dfcc02169577c37912d19cbb01f61e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 9, 2026.
Transparency log