Jonathan
Jonathan

Reputation: 11365

AWS CDK Snapshot testing in Python

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

Answers (1)

Vinícius OA
Vinícius OA

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

Related Questions