skillfed

ops-scenario

Python library providing a state-transition testing API for Operator Framework charms.

ops-scenario v8.8.1 184.6K downloads/30d#10,032 on PyPI265
Permissive license Apache-2.0 Active released

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-scenario

uv

uv add ops-scenario

poetry

poetry add ops-scenario

Installing 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

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersTopic :: Software Development :: Quality AssuranceTopic :: Software Development :: TestingTopic :: Utilities

Tags

juju charm unit testingops charm testing frameworkstate transition testingcharm event simulationjuju state testingops testing librarycharm test harness
jujucharm-testingstate-transition

More Utilities packages