--- id: ops-scenario version: "8.8.1" license: Apache-2.0 license_treatment: permissive maintenance: active --- # ops-scenario — Python library providing a state-transition testing API for Operator Framework charms. License: permissive · Maintenance: active · Downloads: 184.6K/mo ## 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 above — 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 pip install ops-scenario uv add ops-scenario 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_current - Install friction: low - Maintenance: active - Downloads: 184.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags juju charm unit testing, ops charm testing framework, state transition testing, charm event simulation, juju state testing, ops testing library, charm test harness, juju, charm-testing, state-transition [View on SkillFed](https://skillfed.io/packages/ops-scenario) · [View on PyPI](https://pypi.org/project/ops-scenario/)