---
title: "Unit Testing Pulumi programs in Python"
description: "An example that applies unit testing to Python and AWS resources."
url: "https://www.pulumi.com/dev/examples/testing-unit-py/"
image: "https://www.pulumi.com/assets/og/dev/examples/testing-unit-py.png"
---

# Unit Testing Pulumi programs in Python

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

- Source on GitHub: https://github.com/pulumi/examples/tree/master/testing-unit-py

## Get started with this example

This example lives in the [pulumi/examples](https://github.com/pulumi/examples/tree/master/testing-unit-py) repo. Pull down just this directory to follow along:

```bash
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](https://docs.python.org/3/library/unittest.html) test framework to define and run the tests.

## Running the tests

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

   ```bash
   $ 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:

   ```bash
   $ python -m unittest -v
   ```

## Further steps

Learn more about testing Pulumi programs:

- [Testing Guide](https://www.pulumi.com/docs/iac/guides/testing/)
- [Unit Testing Guide](https://www.pulumi.com/docs/iac/guides/testing/unit/)
