Integration Testing Cookbook

This is a “cookbook” of useful techniques and solutions to common problems when integration testing a charm that has been built with the Charmed Operator Framework.

Wait for a single unit of the application to finish installing.

ops_test.model.wait_for_idle(apps=['application_name'], status='active', timeout=60, wait_for_exact_units=1)

Temporarily speed up update-status hooks

Useful for making a test run more quickly:

@contextlib.asynccontextmanager
async def fast_forward(ops_test, interval: str = "10s"):
    # temporarily speed up update-status firing rate
    await ops_test.model.set_config({"update-status-hook-interval": interval})
    yield
    await ops_test.model.set_config({"update-status-hook-interval": "60m"})


async def test_deploy(ops_test: OpsTest):
    async with fast_forward(ops_test):
        await ops_test.model.wait_for_idle(...)

Further reading

Writing Integration Tests for Charmed Operators


Last updated 5 months ago.