[英]AWS CDK Snapshot testing in Python
The CDK Documentation describes how to do snapshot testing in Typescript. CDK 文档描述了如何在 Typescript 中进行快照测试。 How would I go about doing the same thing in Python?
我将如何在 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.似乎没有 cdk-asserts 库的 Python 版本,而且关于如何在 python 中进行 cdk 测试的文档示例也很少。
AWS docs really sucks. AWS 文档真的很烂。 They've created a repo with some testing examples in Python, Java and Typescript.
他们创建了一个包含一些 Python、Java 和Typescript测试示例的存储库。 For snapshot testing, you must use some pytest plugin for that .
对于快照测试,您必须为此使用一些pytest 插件。
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
您必须调用:
pytest <test_file.py> --snapshot-update
Then a __snapshot__
in current directory will be created with the snapshots defined.然后将使用定义的快照在当前目录中创建一个
__snapshot__
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.