Reputation: 11365
The CDK Documentation describes how to do snapshot testing in Typescript. How would I go about doing the same thing in Python?
There doesn't seem to be a Python version of the cdk-asserts library and also there are very few documented examples anywhere of how to do cdk testing in python.
Upvotes: 2
Views: 1034
Reputation: 357
AWS docs really sucks. They've created a repo with some testing examples in Python, Java and Typescript. For snapshot testing, you must use some pytest plugin for that.
Using syrupy's snapshot fixture, you would test like:
def test_something(snapshot):
s = cdk.Stack()
stack = Construct(s, ...)
template = assertions.Template.from_stack(stack)
assert template.to_json() == snapshot
You must call: pytest <test_file.py> --snapshot-update
Then a __snapshot__
in current directory will be created with the snapshots defined.
Upvotes: 2