Skip to main content

A pytest command-line option for pdb breakpoints

Project description

This is an aid to help traditional text editors fire up the debugger and fast-forward to the point of interest. If you already have a solid workflow with breakpoint() snippets and/or the --trace and --pdb options, there’s nothing to see here.

This basically does …

$ pytest --trace spam.py::test_foo
...
(pdb) until 42

or …

def test_foo():
    ...
    pytest.set_trace(header="line 42")

with a few minor conveniences sprinkled in

Simpatico check
  1. You prefer a noninvasive, one-click, carry-me approach to entering the debugger
  2. You like the certainty of stopping offered by the second example above
  3. You like tab completion of variables and attributes
  4. You want inside unittest.TestCase s, your own fixtures, and nested async funcs (all experimental)
Before you try
Check out the newer ptvsd/DAP/pydevd-based extensions for Vim and Emacs. They definitely have the potential to work seamlessly with pytest, VS-Code style. This plugin only launches PDB, the built-in GDB-style debugger.
Don’t install
Unlike proper pytest plugins, this isn’t meant to be installed as a Python package. The editor will instead inject an isolated installation via PYTHONPATH, but only while in use (no internet connection required).
WIPs
Notes/caveats
  1. Unfortunately, this thing has only ever been tried/tested on Linux

  2. It mainly exists for its author to learn about pytest, a decent understanding of which continues to evade

  3. It does not support the -m pytest style of invocation, meaning working directories are not implicitly prepended to sys.path

  4. When hacking on the main pytest plugin, disregard the imperative above and do install:

    (.venv)repo@master$ pip install -e .
    

    If sticking with the included reference integrations, some extra finagling may be required. For example:

    • Disabling “isolated-lib” creation via one of the documented options
    • Manually managing the editor plugin (or making it play nice with your manager)

    If doing your own thing, the usual rules apply, like ensuring the right exec path and env vars have precedence when summoning pytest:

    const pytest = pty.spawn(
        'pytest', ['--break=spam.py:42', nodeid],
        { cwd: rootdir, env: Object.assign({}, process.env, modified) }
    );  // or whatever
    
TODOs
  1. Improve asyncio support
  2. Support class names with non-Test prefixes.
  3. External helper returning --options list

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytest-pdb-break, version 0.0.6
Filename, size File type Python version Upload date Hashes
Filename, size pytest_pdb_break-0.0.6-py3-none-any.whl (14.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pytest-pdb-break-0.0.6.tar.gz (9.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page