How to Test Your Helm Charts with Snapshot Testing
Ever changed one line in your Helm chart and accidentally broke 10 other things? Snapshot testing catches those surprises before they hit…

How to Test Your Helm Charts with Snapshot Testing
Ever changed one line in your Helm chart and accidentally broke 10 other things? Snapshot testing catches those surprises before they hit production.
What is Snapshot Testing?
Think of it like taking a photo of your Helm chart’s output.
- You render your chart once and save the result (the “snapshot”)
- Every time you run tests, the current output is compared to that saved snapshot
- If something changed, the test fails and shows you exactly what’s different
It’s that simple.
Why Use It for Helm Charts?
Helm charts generate Kubernetes YAML. Small changes in values.yaml can cascade into unexpected changes across multiple resources. Snapshot testing gives you a safety net — especially when you have multiple environments like dev, qa, and prod.
Let’s Build It
Project Structure
my-helm-chart/
├── Chart.yaml
├── templates/
│ └── deployment.yaml
├── values/
│ ├── dev.values.yaml
│ ├── qa.values.yaml
│ └── prod.values.yaml
├── pyproject.toml
└── tests/
└── test_snapshots.py
Step 1: Install Dependencies
pip install pytest pytest-snapshot
Or with Poetry:
poetry add — group dev pytest pytest-snapshot
Step 2: Write the Test
Create tests/test_snapshots.py:
import subprocess
import pytest
ENVIRONMENTS = ["dev", "qa", "prod"]
@pytest.fixture
def helm_render():
"""Fixture that renders a Helm chart and returns the output."""
def _render(env):
result = subprocess.run(
[
"helm", "template", "my-release", ".",
"-f", f"values/{env}.values.yaml"
],
capture_output=True,
text=True,
check=True,
)
rendered = result.stdout
# Remove non-deterministic content (chart version changes with each release)
rendered = re.sub(r"^.*helm.sh/chart:.*\n", "", rendered, flags=re.MULTILINE)
return rendered
return _render
@pytest.mark.parametrize("env", ENVIRONMENTS)
def test_helm_chart_output(snapshot, helm_render, env):
"""Compare rendered chart against saved snapshot for each environment."""
rendered = helm_render(env)
snapshot.assert_match(rendered, f"{env}.expected.yaml")
The @pytest.mark.parametrize decorator runs the test once for each environment. One test file covers all three environments.
Step 3: Generate the First Snapshots
Run pytest with the — snapshot-update flag:
pytest — snapshot-update
This creates three snapshot files:
tests/snapshots/test_snapshots/test_helm_chart_output/
├── dev.expected.yaml
├── qa.expected.yaml
└── prod.expected.yaml
Step 4: Run Tests
Now just run:
pytest
Output:
test_snapshots.py::test_helm_chart_output[dev] PASSED
test_snapshots.py::test_helm_chart_output[qa] PASSED
test_snapshots.py::test_helm_chart_output[prod] PASSED
If any environment’s output changed, you’ll see exactly which one failed and what’s different.
Make changes to chart
↓
Run: pytest
↓
┌────┴────┐
│ │
PASS FAIL
│ │
↓ ↓
Done Review diff
│
┌────┴────┐
│ │
Intentional Bug found
│ │
↓ ↓
Run: pytest Fix it
--snapshot-update
Real Example Output
When a test fails, you see exactly what changed and in which environment:
FAILED test_snapshots.py::test_helm_chart_output[prod]
- replicas: 3
+ replicas: 5
No guessing. No surprises.
Tips
- Commit your snapshots — They’re part of your test suite
- Review snapshot changes in code review — Treat them like code changes
- Test all environments — A change that works in dev might break prod
Conclusion
Snapshot testing for Helm charts takes 10 minutes to set up and saves hours of debugging. You’ll catch environment-specific issues before they reach production.
메타데이터
- post_id
- 38d642fe1e28
- slug
- how-to-test-your-helm-charts-with-snapshot-testing-38d642fe1e28
- url
- https://medium.com/@sam-alizadeh/how-to-test-your-helm-charts-with-snapshot-testing-38d642fe1e28
- canonical_url
- https://medium.com/@sam-alizadeh/how-to-test-your-helm-charts-with-snapshot-testing-38d642fe1e28
- author_url
- https://medium.com/@sam-alizadeh
- status
- ok
- fetched_at
- 2026-07-14 07:47:58