Skip to content

Conversation

@james-garner-canonical
Copy link

@james-garner-canonical james-garner-canonical commented Dec 12, 2025

Issue

The ops.testing framework currently exposes the private _CharmSpec class via the Context.charm_spec attribute (canonical/operator#2131). Charm Tech will deprecate this attribute soon (canonical/operator#2219). This charm currently uses charm_spec in one of its tests, so this PR preemptively updates the test to avoid using it.

Solution

The test previously used charm_spec to access the class of the charm being used in the test, in order to modify it to create a version that would fail. This was necessary because the charm classes were defined inside fixtures, and those fixtures were in turn passed through fixtures that wrapped the charm classes in testing.Context.

This PR lifts the class and metadata definitions to the top-level of the e2e test suite, and in-lines the testing.Context calls into the tests, which allows the failing version of the class to be defined by inheritance. The PR isn't as large as it looks -- the first chunk is just shifting the existing content to the top-level.

Checklist

  • I have added or updated relevant documentation. N/A
  • PR title makes an appropriate release note and follows conventional commits syntax.
  • Merge target is the correct branch, and relevant tandem backport PRs opened.

Does this need to be backported anywhere?

Context

N/A

Testing Instructions

The existing tests are only lightly modified in their initial setup, and continue to pass. The test charm classes and metadata can be verified to have only been lifted to the top-level and not otherwise modified.

Upgrade Notes

N/A, only tests are changed

@james-garner-canonical james-garner-canonical marked this pull request as ready for review December 12, 2025 02:19
@james-garner-canonical james-garner-canonical requested a review from a team as a code owner December 12, 2025 02:19
@sed-i
Copy link
Contributor

sed-i commented Dec 12, 2025

Thanks @james-garner-canonical!

@james-garner-canonical
Copy link
Author

The 3.5.0 ops release yesterday includes the deprecation of Context.charm_spec. Is anything further needed in this PR before merging?

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.

2 participants