Skip to main content

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 .bicepparam entry point for the deployment under test

Installation

python -m pip install anthonycmartin-bicep-testing==0.1.5

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="ddbe463a-0554-485d-b589-0b17d60cd38b",
	subscription_id="28c9069e-23e8-47d2-b640-00d2e0f09616",
	resource_group="example-rg",
	location="eastus",
	deployment_name="example-deployment",
)

with BicepTestSession.create("0.46.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.

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 deployment
  • outputs: resolved deployment outputs
  • diagnostics: 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_valid
  • resources
  • correlation_id
  • error (OperationError with code, message, raw_data)

deploy() returns immutable DeployResult for both success and post-submission Azure failures, with:

  • succeeded
  • error, error_code, error_message
  • outputs
  • resources

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

Metadata

Release files for anthonycmartin-bicep-testing 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anthonycmartin-bicep-testing 0.1.5
File Size Uploaded
anthonycmartin_bicep_testing-0.1.5.tar.gz 14.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anthonycmartin-bicep-testing 0.1.5
File Interpreter ABI Platform
anthonycmartin_bicep_testing-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / anthonycmartin_bicep_testing-0.1.5.tar.gz

Download URL anthonycmartin_bicep_testing-0.1.5.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1893c3950de1771f91083401a48b7f0761a3402e5fded7b080fd4fc7e83e2b60
BLAKE2b-256 checksum
How to use checksums
fa21e608d4a16db0effa092acb89794c3983db3c1b03282dd79efc34a3accb85
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 10, 2026.

Transparency log

Release files / anthonycmartin_bicep_testing-0.1.5-py3-none-any.whl

Download URL anthonycmartin_bicep_testing-0.1.5-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27da24f0d4f216f9c45bcae3230d46db0adec22a2e1032ff45a64ea32376c446
BLAKE2b-256 checksum
How to use checksums
8703235e35bc07c3ff3e96549a46060349ce7ad64220a4194da7b3e3d4b52857
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 10, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.6

2 release files

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page