Skip to main content

A pytest command-line option for pdb breakpoints

Project description

This is an aid to help traditional text editors (Vim and Emacs) 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
(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 afforded by the second example above
  3. You like tab completion of variables and attributes
  4. You want inside fixtures, unittest.TestCase’s, and pytest-asyncio items
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, as VS-Code seems to. This plugin merely 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).
  1. Ditch helpers in favor of client/server model
  2. Support arbitrary test names via the "python_functions" and python_classes options
  3. Support FreeBSD
  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. If ever hacking on the main pytest plugin, disregard the above and do install:

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

    Some extra pains may be required to control how changes get reloaded. 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)

    Otherwise, the usual rules apply, like ensuring the right exec path and env vars have precedence when summoning pytest:

    const pytest = pty.spawn(
        'pytest', ['', nodeid],
        { cwd: rootdir, env: Object.assign({}, process.env, modified) }
    );  // or whatever

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.7
Filename, size File type Python version Upload date Hashes
Filename, size pytest_pdb_break-0.0.7-py3-none-any.whl (14.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pytest-pdb-break-0.0.7.tar.gz (10.8 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 DigiCert DigiCert EV certificate StatusPage StatusPage Status page