Skip to main content

Testing the Python library behind great charms

Project description

ops-harness

ops-harness provides Harness, the legacy unit-testing API for charms built with the ops framework. It packages the Harness class as a standalone distribution that ops re-exports as ops.testing.Harness -- the same way ops re-exports the ops-scenario package's state-transition API under ops.testing.

[!IMPORTANT] Harness is deprecated. For new charms, and where reasonable for existing charms, prefer the state-transition testing API in ops.testing (the ops-scenario package). ops-harness exists so that charms that still rely on Harness can continue to do so as the class is removed from the core ops distribution.

  • ops-harness requires Python 3.8 or above.
  • It depends on ops 2.23 or above.

Installation

pip install ops-harness

Or, with uv:

uv add ops-harness

Usage

Add ops-harness to your charm's test dependencies, then import Harness from ops.testing:

from ops.testing import Harness

from charm import MyCharm


def test_config_changed():
    harness = Harness(MyCharm, meta="name: my-charm")
    harness.begin()
    harness.update_config({"log-level": "debug"})
    assert harness.charm.model.config["log-level"] == "debug"
    harness.cleanup()

For the full API, see the ops.testing.Harness reference documentation.

Contributing and developing

Anyone can contribute to ops-harness. See CONTRIBUTING.md for the contribution process, and HACKING.md for how to set up a development environment and run the tests.

Code of conduct

When contributing, you must abide by the Ubuntu Code of Conduct.

License

ops-harness is free software, distributed under the Apache Software License, version 2.0. See LICENSE for details.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ops_harness-0.1.tar.gz (99.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ops_harness-0.1-py3-none-any.whl (47.6 kB view details)

Uploaded Python 3

File details

Details for the file ops_harness-0.1.tar.gz.

File metadata

  • Download URL: ops_harness-0.1.tar.gz
  • Upload date:
  • Size: 99.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for ops_harness-0.1.tar.gz
Algorithm Hash digest
SHA256 bfcd1a6fdd9b35f8adf325dfc5e6ea55dcd628c8039e74b79c9c90b620a4962a
MD5 f600e4f48f547b19838dd8ee512a2607
BLAKE2b-256 1f3d8a591d784ce34042d105c38e0beef926378f8694de6cf393fb56cd49ce27

See more details on using hashes here.

Provenance

The following attestation bundles were made for ops_harness-0.1.tar.gz:

Publisher: publish-pypi.yaml on tonyandrewmeyer/ops-harness

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ops_harness-0.1-py3-none-any.whl.

File metadata

  • Download URL: ops_harness-0.1-py3-none-any.whl
  • Upload date:
  • Size: 47.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for ops_harness-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40eabee66802fd1026bf19140e7fb8b66e8558c5222090df5a297566523cc9fe
MD5 f605777ac163929c5fe5daaab9f1940e
BLAKE2b-256 3aae2f4741c184abbdb8eab493c7742011a079e9898773491880cd0a5ca04a97

See more details on using hashes here.

Provenance

The following attestation bundles were made for ops_harness-0.1-py3-none-any.whl:

Publisher: publish-pypi.yaml on tonyandrewmeyer/ops-harness

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page