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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.