skillfed

pytest-operator

Fixtures for Charmed Operators

pytest-operator v0.43.2 152.5K downloads/30d#10,898 on PyPI10
Permissive license Apache Active released

What it is and what it does

pytest-operator is a pytest plugin designed to simplify writing integration tests for Juju operator charms. It provides an `ops_test` fixture that wraps a libjuju Model and offers helper methods for building charms, managing resources, rendering bundles, and deploying to a Juju environment. The fixture is module-scoped and includes conveniences like automatic async test marking and the ability to abort remaining tests in a module if a critical test fails.

You use it by including it in your test dependencies and then calling methods like `ops_test.build_charm()`, `ops_test.build_resources()`, and `ops_test.model.deploy()` within async test functions. It handles the boilerplate of connecting to a Juju model and provides utilities for rendering Jinja2 templates (for bundle files) and running juju CLI commands directly when needed.

Use it for:

  • Test charm deployment and lifecycle by building a charm locally and verifying it reaches active status.
  • Validate charm resources are correctly built or downloaded and attached during deployment.
  • Render and deploy multi-charm bundles with templated configuration for integration testing.
  • Verify charm behavior after deployment by inspecting model state and application status.
  • Abort a test module early if an initial deployment test fails, marking dependent tests as xfailed.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A pytest plugin that provides fixtures and helpers for writing integration tests of Juju operator charms, including charm building, resource management, and model deployment.

Yes, if you are writing integration tests for Juju operator charms. The plugin is actively maintained, has no known vulnerabilities, uses a permissive license, and provides real value by reducing boilerplate for a specialized testing domain. The low install friction and stable dependency set make it a straightforward addition to a charm testing workflow.

Install

pytest-operator on PyPI

pip

pip install pytest-operator

uv

uv add pytest-operator

poetry

poetry add pytest-operator

Installing pytest-operator

Before you install

Low friction installation; active maintenance with a recent release (2025-10-04) and last commit on 2026-04-09. Depends on pytest, juju, and pytest-asyncio, all standard testing libraries.

License in practice

Apache license (permissive) means you can use this in commercial and open-source projects with minimal restrictions; include a copy of the license and note any modifications.

Quickstart

# In tox.ini or requirements:
pip install pytest-operator

# In your test file:
import pytest

@pytest.mark.abort_on_fail
async def test_build_and_deploy(ops_test):
    my_charm = await ops_test.build_charm(".")
    await ops_test.model.deploy(my_charm)
    await ops_test.model.wait_for_idle()

Requires Python 3.8 or later; assumes you have a Juju environment available for the ops_test fixture to connect to.

Verify before relying

  • Whether the package requires a running Juju controller or if it can mock/stub the Juju connection for unit testing.
  • Performance characteristics when running large numbers of integration tests in parallel.
  • Compatibility with different Juju versions beyond what the classifiers indicate.

Package facts

License Apache (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 6 — ipdb, pytest, pytest-asyncio, pyyaml, juju, jinja2
Maintenance actively maintained — 314 days since the last release
Last repo commit
First released
Downloads 152,528/month — #10,898 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_operator-0.43.2-py3-none-any.whl

Keywords: pytest, py.test, operators, ops

License :: OSI Approved :: Apache Software LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

pytest operator charm testingjuju charm integration testsoperator charm test fixturespytest juju deploymentcharm resource testingoperator integration testing framework
juju-charmsintegration-testingoperator-framework

More Testing packages