Skip to main content

Unit Testing Pulumi programs in Python

An example that applies unit testing to Python and AWS resources.

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set testing-unit-py
cd pulumi-examples/testing-unit-py

An example of writing mock-based unit tests with both infrastructure definition and tests written in Python. The example uses the unittest test framework to define and run the tests.

Running the tests#

  1. Create a Python virtualenv, activate it, and install dependencies:

    Terminal window
    python3 -m venv venv
    source venv/bin/activate
    python -m pip install --upgrade pip
    python -m pip install -r requirements.txt
  2. Run the tests:

Terminal window
python -m unittest -v

Further steps#

Learn more about testing Pulumi programs:

Related

The infrastructure as code platform for any cloud.