Skip to main content

pytest-tf

GitHub License PyPI - Version PyPI - Python Version PyPI - Downloads

Test your OpenTofu and Terraform config using a PyTest plugin.

Usage

Simply add pytest-tf as a dependency, then run pytest with the following configuration options:

  • tf_runner: The path to the program that will build the infrastructure. By default, this is tofu. Options: tofu, terraform.

Check the pytest documentation for more information on how to set ini options. You have multiple options:

You can set it in the command line:

pytest --override-ini tf_runner=terraform

Or you can set it in pyproject.toml:

[tool.pytest.ini_options]
tf_runner = "terraform"

Or you can set it in pytest.ini:

[pytest]
tf_runner = terraform

Or you can set it in tox.ini:

[testenv]
setenv =
    tf_runner = terraform

Note: The --capture=no option is recommended to see the output of the Terraform commands.

Features

  • Fixture: The tf fixture handles the Terraform initialization, plan, apply and destroy steps. The init, plan and apply are run before the test, and the destroy is run after the test. The fixture is a types.SimpleNamespace with the following attributes:

    • state: The Terraform state file as a dict.

    Example:

def test_tf(tf):
    assert tf.state['resources']['aws_instance.example']['type'] == 'aws_instance'
  • Markers: The tf_path marker allows you to specify the path to the Terraform configuration folder. It is recommended you have a terraform folder in your tests folder, and you create a separate folder for each test under it. The marker is a string with the path to the folder.

    Example:

import pytest

@pytest.mark.tf_path('tests/terraform/example')
def test_tf(tf):
    ...

License

This project is licensed under the MIT License - see the LICENSE file for details.

Release files for pytest-tf 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-tf 0.1.0
File Size Uploaded
pytest_tf-0.1.0.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-tf 0.1.0
File Interpreter ABI Platform
pytest_tf-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.6 kB

Release files / pytest_tf-0.1.0.tar.gz

Download URL pytest_tf-0.1.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
26c47523dbeac84b1bc733faea2272b3a3872569d706d58a71956bd1ea13f1fe
BLAKE2b-256 checksum
How to use checksums
05fbb52ff8149bb613bbc8c6aaac83e2016e11b51af024bb9e38bb54c5f4db7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0

Release files / pytest_tf-0.1.0-py3-none-any.whl

Download URL pytest_tf-0.1.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6fc0e900f70b9069e78116ea24367a5cc739facf2741de4f6c5d1c93432d184
BLAKE2b-256 checksum
How to use checksums
5b3dab2fc1c0821cf004b10a5ab07b0c2990256c3a574137bd4ede6d5f6c7702
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page