Pytest: Using ipdb with --pdbcls and tab completion

Created on 20 Sep 2018  路  17Comments  路  Source: pytest-dev/pytest

Hi!

I'm trying to get ipdb and the --pdbcls to work together perfectly. I was wondering if anyone else has been able to do it. I currently have two solutions for two different use cases.

If I set it using --pdbcls=IPython.core.debugger:Pdb then I can use pytest --pdb to get into a shell on exceptions or when I use pytest.set_trace() but neither of them support tab completion and everything ipdb supports.

If I create my own class:

def Debugger():
    import ipdb
    return ipdb

and use that as my pdbcls then I can use pytest.set_trace() with tab completion and all that nice stuff but when I use --pdb I get an exception like this:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/_pytest/main.py", line 178, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File "/usr/local/lib/python3.6/site-packages/_pytest/main.py", line 215, in _main
    config.hook.pytest_runtestloop(session=session)
  File "/usr/local/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.6/site-packages/_pytest/main.py", line 236, in pytest_runtestloop
    item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
  File "/usr/local/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.6/site-packages/_pytest/runner.py", line 66, in pytest_runtest_protocol
    runtestprotocol(item, nextitem=nextitem)
  File "/usr/local/lib/python3.6/site-packages/_pytest/runner.py", line 81, in runtestprotocol
    reports.append(call_and_report(item, "call", log))
  File "/usr/local/lib/python3.6/site-packages/_pytest/runner.py", line 167, in call_and_report
    hook.pytest_exception_interact(node=item, call=call, report=report)
  File "/usr/local/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.6/site-packages/_pytest/debugging.py", line 109, in pytest_exception_interact
    _enter_pdb(node, call.excinfo, report)
  File "/usr/local/lib/python3.6/site-packages/_pytest/debugging.py", line 167, in _enter_pdb
    post_mortem(tb)
  File "/usr/local/lib/python3.6/site-packages/_pytest/debugging.py", line 189, in post_mortem
    class Pdb(pytestPDB._pdb_cls):
TypeError: function() argument 1 must be code, not str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/pytest", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py", line 67, in main
    return config.hook.pytest_cmdline_main(config=config)
  File "/usr/local/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.6/site-packages/_pytest/main.py", line 208, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/usr/local/lib/python3.6/site-packages/_pytest/main.py", line 191, in wrap_session
    config.notify_exception(excinfo, config.option)
  File "/usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py", line 659, in notify_exception
    res = self.hook.pytest_internalerror(excrepr=excrepr, excinfo=excinfo)
  File "/usr/local/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.6/site-packages/_pytest/debugging.py", line 116, in pytest_internalerror
    post_mortem(tb)
  File "/usr/local/lib/python3.6/site-packages/_pytest/debugging.py", line 189, in post_mortem
    class Pdb(pytestPDB._pdb_cls):
TypeError: function() argument 1 must be code, not str

Here are the pytest packages I'm currently using:

pytest==3.8.0
pytest-cov==2.6.0
pytest-django==3.4.2
pytest-sugar==0.9.1
pytest-watch==4.2.0

and python version 3.6.5

debugging

Most helpful comment

I created https://github.com/JBKahn/pytest-ipdb-cls based on a fork and gutting all the things. I want to see if I can think of a good way to add a test for this. Then I can release it.

All 17 comments

def Debugger():
    import ipdb
    return ipdb

isn't a class and so when pytest tries to inherit from it it splodes.

Have you considered trying pytest-ipdb (marked as deprecated) or pdb++?

I got slightly further with:

class IPDB(object):
    def __new__(*a):
        import ipdb
        return ipdb
$ python -mpytest --pdbcls=t2:IPDB test.py --pdb
============================= test session starts ==============================
platform linux -- Python 3.6.5, pytest-3.8.0, py-1.6.0, pluggy-0.7.1
rootdir: /tmp/t, inifile:
collected 1 item                                                               

test.py F
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    def test():
>       assert False
E       assert False

test.py:8: AssertionError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 178, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 215, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 236, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/runner.py", line 66, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/runner.py", line 81, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/runner.py", line 167, in call_and_report
INTERNALERROR>     hook.pytest_exception_interact(node=item, call=call, report=report)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 109, in pytest_exception_interact
INTERNALERROR>     _enter_pdb(node, call.excinfo, report)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 167, in _enter_pdb
INTERNALERROR>     post_mortem(tb)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 197, in post_mortem
INTERNALERROR>     p.reset()
INTERNALERROR> AttributeError: module 'ipdb' has no attribute 'reset'
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 178, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 215, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 236, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/runner.py", line 66, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/runner.py", line 81, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/runner.py", line 167, in call_and_report
INTERNALERROR>     hook.pytest_exception_interact(node=item, call=call, report=report)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 109, in pytest_exception_interact
INTERNALERROR>     _enter_pdb(node, call.excinfo, report)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 167, in _enter_pdb
INTERNALERROR>     post_mortem(tb)
INTERNALERROR>   File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 197, in post_mortem
INTERNALERROR>     p.reset()
INTERNALERROR> AttributeError: module 'ipdb' has no attribute 'reset'

=================================== FAILURES ===================================
_____________________________________ test _____________________________________

    def test():
>       assert False
E       assert False

test.py:8: AssertionError
=============================== warnings summary ===============================
/tmp/t/venv/lib/python3.6/site-packages/IPython/lib/pretty.py:91: DeprecationWarning: IPython.utils.signatures backport for Python 2 is deprecated in IPython 6, which only supports Python 3
  from IPython.utils.signatures import signature

-- Docs: https://docs.pytest.org/en/latest/warnings.html
===================== 1 failed, 1 warnings in 0.45 seconds =====================
Traceback (most recent call last):
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 178, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 215, in _main
    config.hook.pytest_runtestloop(session=session)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 236, in pytest_runtestloop
    item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/runner.py", line 66, in pytest_runtest_protocol
    runtestprotocol(item, nextitem=nextitem)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/runner.py", line 81, in runtestprotocol
    reports.append(call_and_report(item, "call", log))
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/runner.py", line 167, in call_and_report
    hook.pytest_exception_interact(node=item, call=call, report=report)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 109, in pytest_exception_interact
    _enter_pdb(node, call.excinfo, report)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 167, in _enter_pdb
    post_mortem(tb)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 197, in post_mortem
    p.reset()
AttributeError: module 'ipdb' has no attribute 'reset'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/t/venv/lib/python3.6/site-packages/pytest.py", line 77, in <module>
    raise SystemExit(pytest.main())
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/config/__init__.py", line 67, in main
    return config.hook.pytest_cmdline_main(config=config)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 208, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/main.py", line 191, in wrap_session
    config.notify_exception(excinfo, config.option)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/config/__init__.py", line 659, in notify_exception
    res = self.hook.pytest_internalerror(excrepr=excrepr, excinfo=excinfo)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
    return outcome.get_result()
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/tmp/t/venv/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 116, in pytest_internalerror
    post_mortem(tb)
  File "/tmp/t/venv/lib/python3.6/site-packages/_pytest/debugging.py", line 197, in post_mortem
    p.reset()
AttributeError: module 'ipdb' has no attribute 'reset'

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at [email protected]

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

That's interesting! I'll take another stab

@jenn-clarke93 and I found this worked with the most recent version:

class Debugger(object):
    quitting = None

    def set_trace(self, frame):
        import ipdb

        return ipdb.set_trace(frame)

    def reset(self, *args, **kwargs):
        from ipdb.__main__ import _init_pdb

        pdb_obj = _init_pdb()
        pdb_obj.botframe = None  # not sure. exception otherwise at quit
        return pdb_obj.reset(*args, **kwargs)

    def interaction(self, *args, **kwargs):
        from ipdb.__main__ import _init_pdb

        pdb_obj = _init_pdb()
        pdb_obj.botframe = None  # not sure. exception otherwise at quit
        return pdb_obj.interaction(*args, **kwargs)

might be worth packaging that up to a pytest-ipdb2 or something of the sort -- I don't use ipython/ipdb myself but I imagine it would be pretty popular if the current pytest-ipdb doesn't work

True, I might reach out to the owner of the repo to see if I can take over the existing one.

I created https://github.com/JBKahn/pytest-ipdb-cls based on a fork and gutting all the things. I want to see if I can think of a good way to add a test for this. Then I can release it.

FWIW: --pdbcls ipdb:__main__.debugger_cls works with pytest 4.4, i.e. you can specify additional attributes. Not sure if that's the best entrypoint, just what I had found quickly when looking at #5039.

Closing this issue for now.

This appears to be broken in 4.5. Tab completion doesn't work. Had to downgrade to 4.4

I reverted to the snippet I posted above

@conanfanli @JBKahn
Can you provide more input, e.g. git-bisect it?

In my pytest config, I have:

addopts=--pdbcls=ipdb:__main__.debugger_cls

This works fine in version 4.4 but not 4.5. By working fine, I mean if I add

import pytest; pytest.set_trace()

in my test, I should get tab completion.

I've just tried it, and get no tab completion (but a normal tab) with 4.4.2 also.
But with 4.4.0 it works.
757ada2fd2d0f9c5e6026f8ab2ef3c1415e1ade8 broke it (for https://github.com/pytest-dev/pytest/issues/5039).

btw: --pdbcls=ipdb:__main__.debugger_cls is something that I've found quickly only when looking into ipdb - I do not know if there is a better entrypoint.

Some findings:

  1. there is no coloring then also
  2. --pdbcls=IPython.core.debugger:Pdb does not work before already
  3. the following makes it work, i.e. importing it earlier (during argument parsing, like it was done before):
diff --git i/src/_pytest/debugging.py w/src/_pytest/debugging.py
index 3bfd5465f..e4df74e4b 100644
--- i/src/_pytest/debugging.py
+++ w/src/_pytest/debugging.py
@@ -21,6 +21,7 @@ def _validate_usepdb_cls(value):
         raise argparse.ArgumentTypeError(
             "{!r} is not in the format 'modname:classname'".format(value)
         )
+    _import_pdbcls(modname, classname)
     return (modname, classname)

Re-opening, but will not investigate further myself - I recommend using pdbpp instead.. ;)

I think --pdbcls=IPython.terminal.debugger:TerminalPdb should work, but then runs into https://github.com/pytest-dev/pytest/issues/2064 - which appears to be a ipython issue and should be reported there I guess (it creates the TerminalInteractiveShell instance itself).

Closing this a duplicate of #2064, which has more information.

Was this page helpful?
0 / 5 - 0 ratings