`breakpoint()` doesn't work in charm code during unit tests
Problem
When using Scenario for unit tests, calling breakpoint() in charm code does nothing. It only works in test code or when using import pdb; pdb.set_trace() directly.
Root Cause
The ops Framework overrides sys.breakpointhook with a custom implementation that only activates when JUJU_DEBUG_AT environment variable is set. During unit tests, this variable isn't set, so breakpoint() silently returns without doing anything.
Reproduction
- Add
breakpoint()to a charm event handler - Write a scenario test that invokes that handler
- Run
pytest - Breakpoint is never triggered
Hi @nsklikas ! Are you trying to test breakpoint() functionality in your charm, or are you trying to set breakpoints while debugging tests? For the latter, I would have thought using your regular debugger tooling would be more useful than the Ops functionality (which is really meant to help jump into code when running under Juju). For the former, it seems like you'd typically rely on Ops ensuring that it works.
I am trying to use breakpoint in the charm code when running unit tests (scenario). I am not trying to use ops functionality, but ops is overriding the default python breakpoint behavior.
ref: https://github.com/canonical/operator/pull/440
there's a test in test/test_main.py as well.