Skip to main content

Simple, ergonomic Helm manifest fixtures for pytest.

Project description

pytest-helm

pytest-helm makes it easy to test Helm charts in a simple and repeatable fashion.

It runs a helm template command, loads your manifests into a fixture, and then allows you to make simple assertions about it's shape/contents.

Quickstart

Add pytest-helm

uv add pytest-helm

Scaffold out the fixture/test file

We assume you won't have pytest configured for a chart directory, so if that's the case you can run:

uv run pytest-helm --init

That will create two sample test files, a fixture in tests/conftest.py and a test in tests/test_deployment.py.

If you are already using pytest, you can skip this step.

Usage

Define as many fixtures as you'd like in conftest:

# tests/conftest.py
from pytest_helm import manifest_fixture

chart = manifest_fixture(
    "chart",
    ["helm", "template", ".", "-f", "values.yaml"],
)

prod_chart = manifest_fixture(
    "prod_chart",
    ["helm", "template", ".", "-f", "prod-values.yaml"],
)

Write tests to validate the YAML shape/output for different values meets your requirements:

# tests/test_deployments.py
def test_it_provisions_one_replica_by_default(chart):
    api = chart.get("deployment/api-server")
    assert api.spec.replicas == 1

def test_it_provisions_multiple_replicas_in_prod(prod_chart):
    api = prod_chart.get("deployment/api-server")
    assert = api.spec.replicas == 3

Use PDB to programatically inspect your manifests:

def test_idk_what_to_test(chart):
   import pdb; pdb.set_trace()

$ pytest
(Pdb) chart
   ManifestIndex({
        'ConfigMap': ['release-name-base-config'],
        'Deployment': ['release-name-api', 'release-name-worker'],
        'Ingress': ['release-name-app'],
        'Job': ['release-name-db-migrate'],
        'Service': ['release-name-api'],
        'ServiceAccount': ['backend']
   })

(Pdb) chart.get("configmap/release-name-base-config")
Box({'apiVersion': 'v1', 'kind': 'ConfigMap', 'metadata': {'name': 'release-name-base-config'}, 'data': {'EMAIL_FROM': 'foo@bar.com'}})

(Pdb)

Notes:

  • chart.get() is case-insensitive, chart.get("ConfigMap/foo") and chart.get("configmap/foo") are the same thing
  • In the event that two resources have the same name/kind, you are required to pass an apiVersion as well, i.e. v1/ConfigMap/foo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_helm-0.1.1.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_helm-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest_helm-0.1.1.tar.gz.

File metadata

  • Download URL: pytest_helm-0.1.1.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_helm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bb214ccdd0dcbd9d8b21ed68f911e2fc29339a23a412fde109fa19be48f9e88a
MD5 73262a05e0a3b4158e28eb89251150ff
BLAKE2b-256 90ad986b8a03ae1cb9206928a9a7d327fdd36a6463a57ed6a4abae709c7f4518

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_helm-0.1.1.tar.gz:

Publisher: publish.yml on thomasv314/pytest-helm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_helm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_helm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_helm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df92db6e08e6aff0fb8e87e603cc63df44dba06c223f2115f281e8a965c801dc
MD5 a82fc9604ced09152bf8c52a1cbbfdea
BLAKE2b-256 5845078fe9b0daa85321fd4e0abb93e8ddeec2bace3ba6811ee1c6df52f5251c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_helm-0.1.1-py3-none-any.whl:

Publisher: publish.yml on thomasv314/pytest-helm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page