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

Using pytest.set_trace with iPython's TerminalInteractiveShell #3289

Closed
JBKahn opened this issue Mar 6, 2018 · 8 comments
Closed

Using pytest.set_trace with iPython's TerminalInteractiveShell #3289

JBKahn opened this issue Mar 6, 2018 · 8 comments
Labels
plugin: debugging related to the debugging builtin plugin status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity

Comments

@JBKahn
Copy link

JBKahn commented Mar 6, 2018

Hey, I've been doing some fiddling around and haven't been able to make heads or tales of it. When looking at iPython's debugger class, I was able to find a flaw that I thought was causing it but it isn't.

I thought this file was imported at the wrong time, when we were still capturing and _is_tty was the wrong value, but I have verified that even if I hardcode that value, it still falls back to launching a PDB shell instead. I know this is probably more of an iPython issue than a pytest issue but I was wondering if anyone wanted to give me a hand.

This is the way I had tried to use it with the pdbcls arg.
I verified with a print statement in the pip installed package that it was accessing that class.

@JBKahn JBKahn changed the title Using pytest.set_trace with ipdb Using pytest.set_trace with iPython's TerminalInteractiveShell Mar 6, 2018
@JBKahn
Copy link
Author

JBKahn commented Mar 6, 2018

I noticed that if I augment this line to be

        import ipdb;
        ipdb.set_trace(frame)

that works, just trying to figure out how to work that into the class that I'm passing in.

@JBKahn
Copy link
Author

JBKahn commented Mar 6, 2018

passing is giving me an error:
--pdbcls=IPython.terminal.debugger:TerminalPdb
passing this as the class

def Debugger():
    import ipdb
    return ipdb

works and dumps me into a shell but then I cannot recover and it crashes when I try to end the exception

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/_pytest/main.py", line 100, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/_pytest/main.py", line 138, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/__init__.py", line 617, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/_pytest/main.py", line 161, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/__init__.py", line 617, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/_pytest/runner.py", line 64, in pytest_runtest_protocol
INTERNALERROR>     nodeid=item.nodeid, location=item.location,
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/__init__.py", line 617, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/lib/python3.6/site-packages/_pytest/terminal.py", line 315, in pytest_runtest_logfinish
INTERNALERROR>     last_item = len(self._progress_nodeids_reported) == self._session.testscollected
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'testscollected'

@JBKahn
Copy link
Author

JBKahn commented Mar 6, 2018

Seems this issue is somewhat similar to #3170 as downgrading pytest worked. I'll have to identify which caused the failure.

def Debugger():
    import ipdb
    return ipdb

worked as my pdbcls

@nicoddemus
Copy link
Member

Hi @JBKahn,

Can you post your failures please?

@nicoddemus nicoddemus added status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity plugin: debugging related to the debugging builtin plugin labels Mar 6, 2018
@JBKahn
Copy link
Author

JBKahn commented Apr 12, 2018

@nicoddemus it was pytest-sugar.

Using

def Debugger():
    import ipdb
    return ipdb

With
--pdbcls=path:Debugger
Work perfectly.

It would be cool if we could potentially pass a class or a module but this isn't a difficult workaround.

@nicoddemus
Copy link
Member

OK thanks for the follow up!

@mmospanenko
Copy link

Works -s argument for me

@JBKahn
Copy link
Author

JBKahn commented Jul 15, 2018

We don't want to skip capture, so we use the debugger argument because we don't want to use -s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: debugging related to the debugging builtin plugin status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants