pytest-operator
Fixtures for Charmed Operators
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-operatoruv
uv add pytest-operatorpoetry
poetry add pytest-operatorInstalling 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
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
ops-scenarioops-scenario is a state-transition testing…
permissive · top 15,000 on PyPI
opsA Python framework for developing…
permissive · top 15,000 on PyPI
jubilantJubilant wraps the Juju CLI with a…
permissive · top 15,000 on PyPI
coslProvides utilities for COS Lite charms,…
permissive · top 15,000 on PyPI
pytest-factoryboyIntegrates factory_boy with pytest to register…
permissive · top 5,000 on PyPI
pytest-aioA pytest plugin that automatically runs async…
permissive · top 15,000 on PyPI
pytest-markdown-docsA pytest plugin that executes Python code…
permissive · top 15,000 on PyPI
pytest-redisA pytest plugin that provides fixtures for…
copyleft · top 15,000 on PyPI
data-platform-helpersProvides version checking and validation…
permissive · top 15,000 on PyPI
pytest-lazy-fixtureAllows you to use pytest fixtures directly as…
permissive · top 15,000 on PyPI