pudb
pudb copied to clipboard
"Debugger instance already exists" when used in pytest
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:
- install pudb and pytest in venv
- create this
test.py
def test_foo():
breakpoint()
breakpoint()
-
pytest --pdbcls pudb.debugger:Debugger --pdb --capture=no test.py
(following https://documen.tician.de/pudb/starting.html#usage-with-pytest) - First breakpoint is encountered in pudb, press
c
to continue to second one - See error
Expected behavior
The debugger should be called on second breakpoint
Versions
pudb 2022.1.3
Why not use pytest-pudb
? (installable via pip install
)
I thought from the documentation the new way was just adding a few options instead of having to install it.
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
Try without the --pdbcls
.
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
):
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.