This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Wrong traceback for AssertionError while running under pdb
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: pdb.set_trace() clobbering traceback on error
View: 16482
Assigned To: Nosy List: serhiy.storchaka, xtreak
Priority: normal Keywords:

Created on 2018-12-04 10:17 by xtreak, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg331025 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-12-04 10:17
While running under pdb when I have an assertion error after the command continue then  the assertion error is mentioned with the statement under which I have executed continue command in pdb. Below script has an assertion error on assert 1 == 2 but when I execute continue from assert 1 == 1 then it shows the line assert 1 == 1 with the AssertionError. I first noticed this with unittest but seems to be a general issue with assert. This is confusing while debugging unittest failures. 

I searched for issues but couldn't find a related one and this exists on master and 2.7. I assume this is a case where AssertionError doesn't use the current line and uses the one where pdb is executed with continue? I don't know if this is an issue with pdb or assert so I am adding Library as the component.

# Reproducible script

import pdb; pdb.set_trace();

assert 1 == 1

for i in range(10):
    pass

assert 1 == 2

# Executing on master

➜  cpython git:(master) $ ./python.exe /tmp/foo.py
> /tmp/foo.py(3)<module>()
-> assert 1 == 1
(Pdb) c
Traceback (most recent call last):
  File "/tmp/foo.py", line 3, in <module>
    assert 1 == 1
AssertionError
msg331033 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-04 11:19
There is nothing specific for assert and AssertionError. Other example:

import pdb; pdb.set_trace()
x = 1
y = 1/0
msg331045 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-12-04 13:23
Thanks Serhiy, is this a known behavior or issue since it's from 2.7 ? This is highly confusing and misleading as in your example and also while debugging tests that fail at a different line of assertion statement from the current line in pdb which might also be a different assert statement.
msg331063 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-12-04 16:32
Seems this is a known issue and has an open PR https://github.com/python/cpython/pull/6233 . I checked out the PR locally and it works fine on the examples presented though has merge conflicts with master. I am closing it as duplicate of issue16482 that links to other possible issues.
History
Date User Action Args
2022-04-11 14:59:08adminsetgithub: 79586
2018-12-04 16:32:14xtreaksetstatus: open -> closed
superseder: pdb.set_trace() clobbering traceback on error
messages: + msg331063

resolution: duplicate
stage: resolved
2018-12-04 13:23:33xtreaksetmessages: + msg331045
2018-12-04 11:19:24serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg331033
2018-12-04 10:17:13xtreakcreate