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

Don't trap AssertionErrors in user code #154

Closed
dimaqq opened this issue Jul 12, 2024 · 2 comments
Closed

Don't trap AssertionErrors in user code #154

dimaqq opened this issue Jul 12, 2024 · 2 comments
Labels

Comments

@dimaqq
Copy link
Collaborator

dimaqq commented Jul 12, 2024

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(
@tonyandrewmeyer tonyandrewmeyer changed the title Don't trap AssetionErrors in user code Don't trap AssertionErrors in user code Jul 17, 2024
@tonyandrewmeyer
Copy link
Collaborator

See also #76.

@tonyandrewmeyer
Copy link
Collaborator

Moved to canonical/operator#1428

@tonyandrewmeyer tonyandrewmeyer closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants