Skip to content

test: Migrate integration tests from pytest-operator to jubilant#723

Open
tonyandrewmeyer wants to merge 17 commits intocanonical:mainfrom
tonyandrewmeyer:migrate-to-jubilant
Open

test: Migrate integration tests from pytest-operator to jubilant#723
tonyandrewmeyer wants to merge 17 commits intocanonical:mainfrom
tonyandrewmeyer:migrate-to-jubilant

Conversation

@tonyandrewmeyer
Copy link
Copy Markdown
Contributor

@tonyandrewmeyer tonyandrewmeyer commented Mar 7, 2026

Applicable spec: N/A

Overview

This PR migrates the integration tests from pytest-operator and python-libjuju to Jubilant and pytest-jubilant.

Note that this was originally written by AI as part of exploratory work by Charm Tech to see how AI (particularly copilot) can help get charms migrated to Jubilant. This PR is an example of that work (a post will appear on Discourse very soon referencing this PR and will more details). However, I have also reviewed it and made tweaks, so am putting myself as the human in the loop, so to speak.

However, what is needed is review from someone who is familiar with the charm and its tests, which I am not.

I'm opening this against the upstream repo as the CI can't run in my fork, since it needs hosted runners. This will allow verifying that the tests do pass.

Rationale

Using Jubilant allows for simpler and more modern and maintainable tests. Most importantly, it allows running the integration tests against both Juju 3 and Juju 4.

Juju Events Changes

N/A

Module Changes

Only test code is changed.

Library Changes

N/A

Checklist

I don't believe I can add a label as an external contributor.

GitHub Copilot and others added 9 commits March 7, 2026 18:49
Replace pytest-operator/python-libjuju with jubilant and pytest-jubilant
for integration tests. All async patterns converted to synchronous.

Generated with GitHub Copilot (Claude Sonnet 4.6).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
pytest-jubilant already registers this option, so adding it again
causes a ValueError during collection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These options are already registered in tests/conftest.py, causing
ValueError on collection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The requests module is imported by test_charm.py, test_loki.py, and
test_saml.py but was missing from the integration tox env deps.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Jubilant uses 'juju integrate' which requires Juju 3.x. The reusable
workflow defaults to 2.9/stable which doesn't have this command.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Juju 3.6 requires strictly confined microk8s. Set the microk8s
channel to 1.34-strict/stable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jubilant.Juju.run() raises TaskError when the action fails, so the test
must use pytest.raises to catch it and inspect the task from the exception.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tonyandrewmeyer tonyandrewmeyer marked this pull request as ready for review March 19, 2026 06:02
@tonyandrewmeyer tonyandrewmeyer requested a review from a team as a code owner March 19, 2026 06:02
@tonyandrewmeyer tonyandrewmeyer requested review from cbartz and florentianayuwono and removed request for a team March 19, 2026 06:02
Copy link
Copy Markdown

@florentianayuwono florentianayuwono left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you tony!

Comment thread tests/integration/conftest.py
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the charm’s integration test suite from pytest-operator/python-libjuju to jubilant/pytest-jubilant, aligning the tests with newer Juju versions and a more modern testing approach.

Changes:

  • Replace pytest-operator async-based integration tests with synchronous Jubilant-based equivalents.
  • Update tox integration/lint environments to include jubilant + pytest-jubilant and drop pytest-operator/libjuju-related deps.
  • Update CI integration workflow inputs to target specific charm/juju channels.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tox.ini Swaps integration/lint deps to use Jubilant tooling instead of pytest-operator/libjuju.
tests/integration/conftest.py Reworks deployment/integration fixtures to use jubilant.Juju and pytest_jubilant.pack().
tests/integration/test_actions.py Migrates action tests from libjuju actions to Jubilant tasks.
tests/integration/test_charm.py Migrates status checks and remote execs to Jubilant CLI/status APIs.
tests/integration/test_s3.py Migrates S3 assertions and remote pebble plan retrieval to Jubilant CLI/tasks.
tests/integration/test_saml.py Migrates SAML test config/waits to Jubilant while keeping HTTP flow intact.
tests/integration/test_loki.py Migrates model status access and polling to Jubilant, making the test synchronous.
docs/release-notes/artifacts/migrate_to_jubilant.yaml Adds a release-note artifact documenting the testing migration.
.github/workflows/integration_test.yaml Adjusts integration workflow inputs (channel / juju-channel).

Comment thread docs/release-notes/artifacts/migrate_to_jubilant.yaml Outdated
Comment on lines 77 to +80
for target in prometheus_targets:
cmd = f"curl -m 10 http://{target}/metrics"
action = await indico_unit.run(cmd, timeout=15)
# Change this if upgrading Juju lib version to >= 3
# See https://github.com/juju/python-libjuju/issues/707#issuecomment-1212296289
result = action.data
code = result["results"].get("Code")
stdout = result["results"].get("Stdout")
stderr = result["results"].get("Stderr")
assert code == "0", f"{cmd} failed ({code}): {stderr or stdout}"
# CLIError is raised if the command fails, so a successful return means status 200.
juju.cli("exec", "--unit", f"{app}/0", "--", "bash", "-c", cmd)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This existed previously, so is really out of scope for a migration PR, but since the fix is small, I've included it as a drive-by.

@tonyandrewmeyer
Copy link
Copy Markdown
Contributor Author

The license headers check is expecting a license in uv.lock, which seems wrong. I think this is ready, so handing over to you - let me know if there's anything else needed from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants