Python unit testing

How does one unit test python stacks? I dont see any examples in the codebase. Anyone have any pointers or links?


Hi there:

Good news: unit testing support for Python just shipped with our latest release last night. You can find documentation here and a few more examples here. (Shoutout to our summer intern, Mark, for building out this feature for us!)

Thanks for adding support for python testing. There is currently no way to specify a context for the unit tests. We heavily use context params in cdktf.json and access them inside our stacks using app.node.try_get_context.

The does not have any way to pass in a context. Tried using app.node.set_context, but that does not work either with

Any pointers on how we can test python stacks that use context parameters?


Hi @pchaganti :wave:

Could you share a short example which does not work? The Testing tool uses app.node.setContext() internally (in TypeScript, but set_context in Python should equal that same call).

There are not enough examples in Python, what about isolated Construct testing?