Skip to content

Wrong traceback for AssertionError while running under pdb #79586

Closed

Description

@tirkarthi
BPO 35405
Nosy @serhiy-storchaka, @tirkarthi
Superseder
  • bpo-16482: pdb.set_trace() clobbering traceback on error
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-12-04.16:32:14.269>
    created_at = <Date 2018-12-04.10:17:13.643>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'Wrong traceback for AssertionError while running under pdb'
    updated_at = <Date 2018-12-04.16:32:14.268>
    user = 'https://github.com/tirkarthi'

    bugs.python.org fields:

    activity = <Date 2018-12-04.16:32:14.268>
    actor = 'xtreak'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-12-04.16:32:14.269>
    closer = 'xtreak'
    components = ['Library (Lib)']
    creation = <Date 2018-12-04.10:17:13.643>
    creator = 'xtreak'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35405
    keywords = []
    message_count = 4.0
    messages = ['331025', '331033', '331045', '331063']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'xtreak']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '16482'
    type = 'behavior'
    url = 'https://bugs.python.org/issue35405'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    Activity

    1. tirkarthi commented on Dec 4, 2018

      @tirkarthi
      MemberAuthor

      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
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Dec 4, 2018
    3. serhiy-storchaka commented on Dec 4, 2018

      @serhiy-storchaka
      Member

      There is nothing specific for assert and AssertionError. Other example:

      import pdb; pdb.set_trace()
      x = 1
      y = 1/0
    4. tirkarthi commented on Dec 4, 2018

      @tirkarthi
      MemberAuthor

      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.

    5. tirkarthi commented on Dec 4, 2018

      @tirkarthi
      MemberAuthor

      Seems this is a known issue and has an open PR #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 bpo-16482 that links to other possible issues.

    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of life3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions