Skip to content
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

Better Scenario error message surfacing #1428

Open
tonyandrewmeyer opened this issue Oct 10, 2024 · 0 comments
Open

Better Scenario error message surfacing #1428

tonyandrewmeyer opened this issue Oct 10, 2024 · 0 comments
Labels
feature New feature or request needs design needs more thought or spec testing Related to ops.testing

Comments

@tonyandrewmeyer
Copy link
Contributor

Wrapping operator-raised errors with UncaughtCharmError can be misleading. Reconsider that choice and possibly let the charm errors bubble up.

Given this code:

class SomeCharm(ops.CharmBase):
    ...
    def _on_relation(self, event):
        assert event.something == some_sanity_check

I'd expect to run pytest --pdb and get dropped into this failing assertion line.

Instead, I'm getting:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB post_mortem >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /code/hexanator/.tox/unit/lib/python3.12/site-packages/scenario/runtime.py(469)exec()
-> raise UncaughtCharmError(
(Pdb)

And I can't get to the original line that triggered the exception.

Here's a cleaned up back trace for reference:

_pytest/python.py(162)pytest_pyfunc_call()
-> result = testfunction(**testargs)

tests/unit/test_scenario.py(56)test_rate_limit()
-> ctx.run(ctx.on.relation_created(relation), initial_state)

scenario/context.py(613)run()
-> with self._run_event(event=event, state=state) as ops:

contextlib.py(158)__exit__()
-> self.gen.throw(value)

scenario/context.py(598)_run_event()
-> with self._run(event=event, state=state) as ops:

contextlib.py(158)__exit__()
-> self.gen.throw(value)

scenario/context.py(660)_run()
-> with runtime.exec(

contextlib.py(158)__exit__()
-> self.gen.throw(value)

scenario/runtime.py(469)exec()
-> raise UncaughtCharmError(

Moved from canonical/ops-scenario#76 and canonical/ops-scenario#154

@tonyandrewmeyer tonyandrewmeyer added feature New feature or request needs design needs more thought or spec labels Oct 10, 2024
@benhoyt benhoyt added the testing Related to ops.testing label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request needs design needs more thought or spec testing Related to ops.testing
Projects
None yet
Development

No branches or pull requests

2 participants