Skip to content

pdb prompt unusable if doctests ran first (macOS and Python 3) #985

@jaraco

Description

@jaraco

Consider this simple test:

">>> 3\n3"

def test_stuff():
    import pdb; pdb.set_trace()

Create a virtualenv on Python 3.4.3, install pytest 2.7.2 and py 1.4.30 and run py.test:

(pytest) $ py.test
====================================== test session starts =======================================
platform darwin -- Python 3.4.3 -- py-1.4.30 -- pytest-2.7.2
rootdir: /Users/jaraco/foo, inifile: 
collected 1 items 

test_stuff.py 
>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
--Return--
> /Users/jaraco/foo/test_stuff.py(4)test_stuff()->None
-> import pdb; pdb.set_trace()
(Pdb) q
F

============================================ FAILURES ============================================
___________________________________________ test_stuff ___________________________________________

    def test_stuff():
>       import pdb; pdb.set_trace()

test_stuff.py:4: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/bdb.py:52: in trace_dispatch
    return self.dispatch_return(frame, arg)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pdb.Pdb object at 0x102a3f7f0>, frame = <frame object at 0x102a54848>, arg = None

    def dispatch_return(self, frame, arg):
        if self.stop_here(frame) or frame == self.returnframe:
            # Ignore return events in generator except when stepping.
            if self.stopframe and frame.f_code.co_flags & CO_GENERATOR:
                return self.trace_dispatch
            try:
                self.frame_returning = frame
                self.user_return(frame, arg)
            finally:
                self.frame_returning = None
>           if self.quitting: raise BdbQuit
E           bdb.BdbQuit

/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/bdb.py:96: BdbQuit
==================================== 1 failed in 1.95 seconds ====================================

Everything's fine - the pdb prompt is displayed and works as expected. However, invoke pytest with --doctest-modules, and the story is different.

(pytest) $ py.test --doctest-modules
====================================== test session starts =======================================
platform darwin -- Python 3.4.3 -- py-1.4.30 -- pytest-2.7.2
rootdir: /Users/jaraco/foo, inifile: 
collected 2 items 

test_stuff.py .
>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
--Return--
> /Users/jaraco/foo/test_stuff.py(4)test_stuff()->None
-> import pdb; pdb.set_trace()
^D
F

============================================ FAILURES ============================================
___________________________________________ test_stuff ___________________________________________

    def test_stuff():
>       import pdb; pdb.set_trace()

test_stuff.py:4: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/bdb.py:52: in trace_dispatch
    return self.dispatch_return(frame, arg)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pdb.Pdb object at 0x102a51be0>, frame = <frame object at 0x102af8248>, arg = None

    def dispatch_return(self, frame, arg):
        if self.stop_here(frame) or frame == self.returnframe:
            # Ignore return events in generator except when stepping.
            if self.stopframe and frame.f_code.co_flags & CO_GENERATOR:
                return self.trace_dispatch
            try:
                self.frame_returning = frame
                self.user_return(frame, arg)
            finally:
                self.frame_returning = None
>           if self.quitting: raise BdbQuit
E           bdb.BdbQuit

/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/bdb.py:96: BdbQuit
=============================== 1 failed, 1 passed in 8.34 seconds ===============================

Although the code stops in the right place, the pdb prompt does not appear. Keystrokes appear to be ignored. Only sending an EOF (^d) allows the test to fail and pytest to exit.

This issue seems to have emerged recently, though I can't imagine what could be causing it. I've tested in a virtualenv, tried upgrading and downgrading pytest, and tried older setuptools versions.

What's the next step to troubleshoot?

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform: macmac platform-specific problemstatus: help wanteddevelopers would like help from experts on this topic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions