What's Changed
This release adds a state-transition testing API for unit tests, formerly known as Scenario (many thanks to @PietroPasotti for his work developing and maintaining the library). Harness is still available, but we encourage all charmers to use the new API for unit tests going forward. The API is an optional install, for example: pip install ops[testing]
, so that the test API code does not get bundled into the charms. All of the classes that you would previously find when using ops-scenario
in the scenario
namespace can then be found in ops.testing
. For example:
from ops import testing
ctx = testing.Context(MyCharm)
state = ctx.run(ctx.on.start(), testing.State(leader=True))
assert state.unit_status == testing.ActiveStatus()
There are also two improvements to Juju Secrets: firstly, the .id
of a Secret
will always include the model UUID, so it can be reliably used for cross-model relations. A more significant change is that, previously, if a charm called set_contents()
and set_info()
in the same hook (even if not the same event handler, or in a deferred event handler) only the last call would have any effect. This is now changed so that the calls accumulate - you can set both content and metadata in the same hook, and also if you set_contents()
twice the contents will be combined. The Juju team intend to make this the secret-set
behaviour in the future as well.
Additionally, ops.main
is now type hinted correctly and will no longer require a type: ignore
directive from users!
Features
- Optionally install Scenario with
ops[testing]
and expose the names in ops.testing in #1381 - Change ops.main() so that you don't need to
type: ignore
it in #1345 - Expand the secret ID out to the full URI when only given the ID in #1358
- Add a JujuVersion property for Pebble log forwarding to Loki in #1370
- Pre-emptively raise
InvalidStatusError
instead of waiting for Juju:
Fixes
- Fix type of
StatusBase
subclasses by callingStatusBase.register
in__init_subclass__
in #1383 Secret.set_info
andSecret.set_content
can be called in the same hook in #1373
Documentation
- Add top-level intro and module-level intros in #1320
- Update the links to the Pebble docs in #1362
- Note about repeatedly setting secret value in Juju 3.6 in #1366
config-changed
is triggered by Juju trust in #1357- Typo on
CharmBase
inheritance example by @theofpa in #1349 - Docs: move Pebble to a separate page in #1392
Continuous Integration
- Periodically run the unit tests of all GitHub-hosted published charms in #1365
- Update the TIOBE reporting for the changes in coverage calculation in #1367
- Spell-check the code as part of linting in #1388
- Run the smoke tests on a schedule in #1387
Testing
- Fix tests that leaked environment variables in #1385
Refactoring
- Move the content of
ops.testing
toops._private.harness
in #1369 - Keep the
unittest.mock
names in the 'mock' namespace in #1379 - Deprecate
StatusBase.register
decorator in #1384
Chores
- Note Juju version on legacy workaround in #1355
- Re-enable test now that Pebble directory permissions are fixed in #1363
- Generate warnings for events that will be removed in Juju 4.0 in #1374
New Contributors
Full Changelog: 2.16.1...2.17.0