-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cleanup testing.Context signature #1492
Comments
Some possible alternatives to #1497: Just warnSomething like this (with some of the better docs from #1497, a mention in the Context docs, and a test): diff --git a/testing/src/scenario/context.py b/testing/src/scenario/context.py
index 411beed9..5f053527 100644
--- a/testing/src/scenario/context.py
+++ b/testing/src/scenario/context.py
@@ -510,6 +510,11 @@ class Context(Generic[CharmType]):
else:
if not meta:
meta = {"name": str(charm_type.__name__)}
+ warnings.warn(
+ "No meta provided: only the charm name is set.",
+ RuntimeWarning,
+ stacklevel=2,
+ ) Deprecate all three, add from_yaml to replaceEmit deprecation warnings if class Context[...]:
...
@classmethod
def from_yaml(charm_type: ..., charmcraft_yaml: dict) -> Context[...]:
# private attributes to pass the things, or do it post __init__ or whatever
return charm_type()
@classmethod
def from_legacy_yaml(charm_type: ..., meta: dict, *, config: dict|None, actions: dict|None) -> Context[...]:
... Although the Deprecate all three, use charmcraft to replaceEmit deprecation warnings if Autoload unless NoneA Validate the config YAMLIf the issue is particularly with Would people providing something like We could do this as well as other things. |
Scenario's Context object was designed with the old 'metadata/actions/config.yaml`s in mind.
Nowadays we have a single charmcraft.yaml, which makes the signature obsolete and confusing.
I recently helped someone debug this code:
which failed with a strange AttributeError caused by the charm attempting to
observe(self.on.foo_relation_changed)
.The reason is that Context will only attempt to autoload meta/actions/config from the yaml files IF the user doesn't specify any of the
meta, config, actions
Context params.The fix was:
But it was not obvious.
It's not clear that the 'config' param in Context doesn't mean "juju config" but "the config section in charmcraft.yaml".
Can we improve this without breaking backwards compatibility?
The text was updated successfully, but these errors were encountered: