File ‘tests/integration/’

The tests/integration/ file is the companion to src/ for integration testing.

This file is created automatically by charmcraft init and it is pre-populated with standard constructs used by pytest-operator, similar to the below:

#!/usr/bin/env python3
# Copyright 2023 Ubuntu
# See LICENSE file for licensing details.

import asyncio
import logging
from pathlib import Path

import pytest
import yaml
from pytest_operator.plugin import OpsTest

logger = logging.getLogger(__name__)

METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())

async def test_build_and_deploy(ops_test: OpsTest):
    """Build the charm-under-test and deploy it together with related charms.

    Assert on the unit status before any relations/configurations take place.
    # Build and deploy charm from local source folder
    charm = await ops_test.build_charm(".")
    resources = {
        "some-container-image": METADATA["resources"]["some-container-image"]["upstream-source"]

    # Deploy the charm and wait for active/idle status
    await asyncio.gather(
        ops_test.model.deploy(charm, resources=resources, application_name=APP_NAME),
            apps=[APP_NAME], status="active", raise_on_blocked=True, timeout=1000

Last updated 5 months ago. Help improve this document in the forum.