Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hydrargyrum opened this issue Jun 19, 2023 · 5 comments · May be fixed by #667
Open

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

hydrargyrum opened this issue Jun 19, 2023 · 5 comments · May be fixed by #667
Labels

Comments

@hydrargyrum
Copy link

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()
  1. pytest --pdbcls pudb.debugger:Debugger --pdb --capture=no test.py (following https://documen.tician.de/pudb/starting.html#usage-with-pytest)
  2. First breakpoint is encountered in pudb, press c to continue to second one
  3. See error

Expected behavior

The debugger should be called on second breakpoint

Versions

pudb 2022.1.3

@inducer
Copy link
Owner

inducer commented Jun 19, 2023

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

@hydrargyrum
Copy link
Author

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

@hydrargyrum
Copy link
Author

hydrargyrum commented Jun 19, 2023

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
Copy link
Owner

inducer commented Jun 19, 2023

Try without the --pdbcls.

@souliane
Copy link

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.

hwalinga added a commit to hwalinga/pudb that referenced this issue Nov 29, 2024
…during postmortem.

This fixes inducer#607. Making the Debugger a singleton should be enough to fix inducer#607.
HOWEVER, pytest def postmortem() calls .reset() which reset the stopframe.
Somehow, this causes the debugger to stop somewhere inside internal debugger source code,
instead of in the code the postmortem should be done.

So, this also includes an overrid eof the .reset() method and detects when the debugger
is already running and does not reset the stopframe. See also inducer#67.
hwalinga added a commit to hwalinga/pudb that referenced this issue Nov 29, 2024
…during postmortem.

This fixes inducer#607. Making the Debugger a singleton should be enough to fix inducer#607.
HOWEVER, pytest def postmortem() calls .reset() which resets the stopframe.
Somehow, this causes the debugger to stop somewhere inside internal debugger source code,
instead of in the code the postmortem should be done.

So, this also includes an override of the .reset() method and detects when the debugger
is already running and does not reset the stopframe. See also inducer#67.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants