Skip to content

breakpoint() doesn't work in charm code during unit tests #2166

@nsklikas

Description

@nsklikas

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

  1. Add breakpoint() to a charm event handler
  2. Write a scenario test that invokes that handler
  3. Run pytest
  4. Breakpoint is never triggered

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions