ops-scenario
Python library providing a state-transition testing API for Operator Framework charms.
What it is and what it does
ops-scenario is a testing library that sits between your code and the Ops framework, letting you write unit tests that simulate Juju state transitions without running a full Juju deployment. You arrange an initial state (including relations, containers, secrets, and config), emit an event through a test context, and assert on the resulting state and any logged output. The library is designed to run at unit-test speeds while covering higher-level behavior than typical unit tests would.
It works by providing test doubles for Juju objects—State, Context, Relation, Container, Secret, and others—that you compose into a scenario. Tests follow the arrange/act/assert pattern, making them straightforward to write and read. The package is tightly integrated with ops itself; when ops-scenario is installed, its classes are exposed through the ops.testing namespace, so you import from ops rather than directly from ops-scenario.
Use it for:
- Test that a charm transitions to ActiveStatus after receiving a start event with minimal setup.
- Verify charm behavior when relations change, including data exchange between units and peer relations.
- Simulate container readiness and workload version changes to test container-aware charm logic.
- Test secret handling by arranging secrets in the initial state and asserting on charm actions.
- Validate charm configuration changes by including config in the input state and checking the output.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
ops-scenario is a state-transition testing framework for Ops charms that lets you write unit tests by arranging a Juju state, emulating an event, and asserting on the resulting state without needing a full Juju installation.
Yes. ops-scenario is actively maintained, has no known vulnerabilities, carries a permissive license, and is the recommended testing approach for Ops charms. It has low install friction and is designed to integrate seamlessly with ops itself. Install it if you are writing or maintaining Ops charms and want to test them without a full Juju setup.
Install
ops-scenario on PyPI
pip
pip install ops-scenariouv
uv add ops-scenariopoetry
poetry add ops-scenarioInstalling ops-scenario
Before you install
Low install friction with three straightforward runtime dependencies (ops, PyYAML, typing_extensions). The package is actively maintained with a recent release and no known vulnerabilities, making it reliable for test environments.
License in practice
Licensed under Apache-2.0 (permissive), so you can freely use, modify, and distribute code that depends on it in both open and closed projects without restriction.
Quickstart
# Install via ops[testing] extra in pyproject.toml:
# test = ['ops[testing]<4.0']
from ops import testing
ctx = testing.Context(MyCharm)
state_in = testing.State()
state_out = ctx.run(ctx.on.start(), state_in)
assert state_out.unit_status == testing.ActiveStatus()
Requires Python 3.10 or later; intended to be installed as the testing extra of ops, not directly.
Verify before relying
- Whether ops-scenario can be installed standalone or only via the ops[testing] extra.
- Exact compatibility matrix between ops-scenario versions and ops versions beyond the 'matching minor and bugfix' statement.
- Whether the testing.Context, testing.State, and related classes are provided by ops-scenario or by ops itself.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — ops, PyYAML, typing_extensions |
| Maintenance | actively maintained — 15 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 184,553/month — #10,032 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ops_scenario-8.8.1-py3-none-any.whl
Keywords: juju, test
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
opsA Python framework for developing…
permissive · top 15,000 on PyPI
pytest-operatorA pytest plugin that provides fixtures and…
permissive · top 15,000 on PyPI
jubilantJubilant wraps the Juju CLI with a…
permissive · top 15,000 on PyPI
jujuA Python library providing asynchronous…
permissive · top 15,000 on PyPI
coslProvides utilities for COS Lite charms,…
permissive · top 15,000 on PyPI
charmlibs-pathopsProvides a pathlib-like interface for reading…
permissive · top 15,000 on PyPI
charmcraftlocalPacks Juju charms with local Python package…
unclear · top 15,000 on PyPI
reactivexRxPY is a library for building asynchronous and…
permissive · top 5,000 on PyPI
genie.libs.opsGenie Libs Ops provides a library component for…
permissive · top 15,000 on PyPI
tox-dockerA tox plugin that manages Docker container…
permissive · top 15,000 on PyPI