canonical / ops-scenario

State-transition testing SDK for Operator Framework Juju charms.
Apache License 2.0
10 stars 7 forks source link

Don't trap AssertionErrors in user code #154

Open dimaqq opened 2 months ago

dimaqq commented 2 months ago

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 commented 2 months ago

See also #76.