Skip to content

cleanup testing.Context signature #1492

Closed as duplicate
Closed as duplicate
@PietroPasotti

Description

@PietroPasotti

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:

def test_foo():
    ctx = Context(MyCharm, config={"foo": "bar"})
    ctx.run(..., State())

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:

def test_foo():
    ctx = Context(MyCharm)
    ctx.run(..., State(config={"foo": "bar"}))

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions