test: refactor e2e unit tests to avoid ops.testing.Context.charm_spec #355
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
The
ops.testingframework currently exposes the private_CharmSpecclass via theContext.charm_specattribute (canonical/operator#2131). Charm Tech will deprecate this attribute soon (canonical/operator#2219). This charm currently usescharm_specin one of its tests, so this PR preemptively updates the test to avoid using it.Solution
The test previously used
charm_specto 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 intesting.Context.This PR lifts the class and metadata definitions to the top-level of the e2e test suite, and in-lines the
testing.Contextcalls 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/ADoes 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