Skip to content

Traceback with --pdb refers to previous pdb.set_trace() #3237

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

Closed
blueyed opened this issue Feb 19, 2018 · 2 comments
Closed

Traceback with --pdb refers to previous pdb.set_trace() #3237

blueyed opened this issue Feb 19, 2018 · 2 comments
Labels
plugin: debugging related to the debugging builtin plugin type: bug problem that needs to be addressed

Comments

@blueyed
Copy link
Contributor

blueyed commented Feb 19, 2018

Given t/test_pdb_offset.py:

def raises():
    raise Exception('outer')


def test_pdb_offset():
    __import__('pdb').set_trace()
    print(1)

    raises()

Running pytest t/test_pdb_offset.py --tb=short --pdb result in:

==================================== test session starts ====================================
platform linux -- Python 3.6.4, pytest-3.4.1.dev51+gb486e129, py-1.5.2, pluggy-0.6.0
rootdir: …/Vcs/pytest, inifile: tox.ini
collected 1 item                                                                            

t/test_pdb_offset.py 
>>>>>>>>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>
> …/Vcs/pytest/t/test_pdb_offset.py(7)test_pdb_offset()
-> print(1)
(Pdb) c
1
F
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
t/test_pdb_offset.py:7: in test_pdb_offset
    print(1)
t/test_pdb_offset.py:2: in raises
    raise Exception('outer')
E   Exception: outer
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> …/Vcs/pytest/t/test_pdb_offset.py(2)raises()
-> raise Exception('outer')
(Pdb) c
                                                                                      [100%]
================================== short test summary info ==================================
FAIL t/test_pdb_offset.py::test_pdb_offset

Notice the first entry in the traceback (t/test_pdb_offset.py:7), which refers to the line after the pdb.set_trace(), but it should be the line where raises gets called.

pytest 3.4.1.dev51+gb486e129.

@blueyed blueyed added type: bug problem that needs to be addressed plugin: debugging related to the debugging builtin plugin labels Feb 19, 2018
@blueyed
Copy link
Contributor Author

blueyed commented Feb 19, 2018

(I can see this being useful as-is in some way, since it gets used when going up/down also inside pdb then.
pdbpp displays a -> for the line after the set_trace, and >> for the line where the exception is coming through.)

@blueyed
Copy link
Contributor Author

blueyed commented Mar 27, 2018

This is a Python issue.
A PR to fix this is being evaluated at https://bugs.python.org/issue24565 / python/cpython#6233.

Test script:

import sys
import traceback


def f():
    print(1)
    if len(sys.argv) > 1:
        __import__('pdb').set_trace()
    print(2)
    raise Exception()


try:
    f()
except Exception as exc:
    print(exc)
    t = sys.exc_info()[2]
    if hasattr(t, '__traceback__'):
        assert t == exc.__traceback__
    traceback.print_tb(t)
    assert t.tb_lineno == 14, 'tb_lineno is off: %s' % t.tb_lineno
    assert t.tb_next.tb_lineno == 10, 'tb_next.tb_lineno is off: %s' % (
        t.tb_next.tb_lineno)

I think it could be addressed / fixed in pytest already in a similar way like pdbpp remembers the correct location: https://github.com/antocuni/pdb/blob/b7e789b836340ecbc131e26f8fd93d74fe652297/pdb.py#L234-L239.

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 type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant