inducer / pudb

Full-screen console debugger for Python
https://documen.tician.de/pudb/
Other
2.94k stars 226 forks source link

"Debugger instance already exists" when used in pytest #607

Open hydrargyrum opened 1 year ago

hydrargyrum commented 1 year ago

Describe the bug

When 2 breakpoints are encountered in pytest with pudb set up, this error pops: Debugger instance already exists

To Reproduce

Steps to reproduce the behavior:

  1. install pudb and pytest in venv
  2. create this test.py
    def test_foo():
    breakpoint()
    breakpoint()
  3. pytest --pdbcls pudb.debugger:Debugger --pdb --capture=no test.py (following https://documen.tician.de/pudb/starting.html#usage-with-pytest)
  4. First breakpoint is encountered in pudb, press c to continue to second one
  5. See error

Expected behavior

The debugger should be called on second breakpoint

Versions

pudb 2022.1.3

inducer commented 1 year ago

Why not use pytest-pudb? (installable via pip install)

hydrargyrum commented 1 year ago

I thought from the documentation the new way was just adding a few options instead of having to install it.

hydrargyrum commented 1 year ago

Actually, it's not working very well either. After installing it and running pytest --pudb test.py --pdbcls pudb.debugger:Debugger, I get the same error, but within pudb this time

It works fine with pytest-pudb installed (else it fails) and then running PYTHONBREAKPOINT="pudb.set_trace" pytest test.py, this is all very confusing and not matching documentation

inducer commented 1 year ago

Try without the --pdbcls.

souliane commented 1 year ago

I can't reproduce with 2 breakpoint(), but with this instead:

def test_foo():
    breakpoint()
    raise Exception

And running with the same command: pytest --pdbcls pudb.debugger:Debugger --pdb --capture=no test.py It fails with:

  File "[...]/.venv/lib/python3.11/site-packages/pudb/debugger.py", line 196, in __init__
    raise ValueError("a Debugger instance already exists")
ValueError: a Debugger instance already exists

I expect to see this instead (here I pressed already e): image

The issue can be fixed by commenting these two lines here:

        if Debugger._current_debugger:
           raise ValueError("a Debugger instance already exists")

But I assume that this fix is too dirty to be committed... yet I don't understand why this check is needed, for me it works fine (better) without it.