Skip to content

Failures in test_doctest (due to nonempty .pdbrc) #120109

Description

@skirpichev

Bug report

Bug description:

I rarely run whole test suite locally, so I'm not sure when it was broken. IIRC, after merging new repl.

BTW, setting PYTHON_BASIC_REPL doesn't help.

$ cat ~/.pdbrc
alias si from cmath import sin;; sin(%1)
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 12 (bookworm)
Release:        12
Codename:       bookworm
$ ./configure -q && make -s
[just stuff from 108562]
$ ./python -m test test_doctest -v
[...]
======================================================================
FAIL: test_debug (test.test_doctest.test_doctest)
Doctest: test.test_doctest.test_doctest.test_debug
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sk/src/cpython/Lib/doctest.py", line 2327, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for test.test_doctest.test_doctest.test_debug
  File "/home/sk/src/cpython/Lib/test/test_doctest/test_doctest.py", line 1992, in test_debug

----------------------------------------------------------------------
File "/home/sk/src/cpython/Lib/test/test_doctest/test_doctest.py", line 2010, in test.test_doctest.test_doctest.test_debug
Failed example:
    try: doctest.debug_src(s)
    finally: sys.stdin = real_stdin
Expected:
    > <string>(1)<module>()
    (Pdb) next
    12
    --Return--
    > <string>(1)<module>()->None
    (Pdb) print(x)
    12
    (Pdb) continue
Got:
    (Pdb) next
    12
    --Return--
    > <string>(1)<module>()->None
    (Pdb) print(x)
    12
    (Pdb) continue


======================================================================
FAIL: test_pdb_set_trace (test.test_doctest.test_doctest)
Doctest: test.test_doctest.test_doctest.test_pdb_set_trace
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sk/src/cpython/Lib/doctest.py", line 2327, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for test.test_doctest.test_doctest.test_pdb_set_trace
  File "/home/sk/src/cpython/Lib/test/test_doctest/test_doctest.py", line 2024, in test_pdb_set_trace

----------------------------------------------------------------------
File "/home/sk/src/cpython/Lib/test/test_doctest/test_doctest.py", line 2057, in test.test_doctest.test_doctest.test_pdb_set_trace
Failed example:
    try: runner.run(test)
    finally: sys.stdin = real_stdin
Expected:
    > <doctest foo-bar@baz[2]>(1)<module>()
    -> import pdb; pdb.set_trace()
    (Pdb) print(x)
    42
    (Pdb) continue
    TestResults(failed=0, attempted=3)
Got:
    (Pdb) print(x)
    42
    (Pdb) continue
    TestResults(failed=0, attempted=3)
----------------------------------------------------------------------
ile "/home/sk/src/cpython/Lib/test/test_doctest/test_doctest.py", line 2085, in test.test_doctest.test_doctest.test_pdb_set_trace
Failed example:
    try:
        runner.run(test)
    finally:
        sys.stdin = real_stdin
Expected:
    > <doctest test.test_doctest.test_doctest.test_pdb_set_trace[9]>(3)calls_set_trace()
    -> import pdb; pdb.set_trace()
    (Pdb) print(y)
    2
    (Pdb) up
    > <doctest foo-bar@baz[1]>(1)<module>()
    -> calls_set_trace()
    (Pdb) print(x)
    1
    (Pdb) continue
    TestResults(failed=0, attempted=2)
Got:
    (Pdb) print(y)
    2
    (Pdb) up
    > <doctest foo-bar@baz[1]>(1)<module>()
    -> calls_set_trace()
    (Pdb) print(x)
    1
    (Pdb) continue
    TestResults(failed=0, attempted=2)
----------------------------------------------------------------------
----------------------------------------------------------------------
File "/home/sk/src/cpython/Lib/test/test_doctest/test_doctest.py", line 2123, in test.test_doctest.test_doctest.test_pdb_set_trace
Failed example:
    try: runner.run(test)
    finally: sys.stdin = real_stdin
    # doctest: +NORMALIZE_WHITESPACE
Expected:
    > <doctest foo-bar@baz[1]>(3)g()
    -> import pdb; pdb.set_trace()
    (Pdb) step
    --Return--
    > <doctest foo-bar@baz[1]>(3)g()->None
    -> import pdb; pdb.set_trace()
    (Pdb) list
      1     def g(x):   
      2         print(x+3)
      3  ->     import pdb; pdb.set_trace()
    [EOF]
    (Pdb) next
    --Return--
    > <doctest foo-bar@baz[0]>(2)f()->None
    -> g(x*2)
    (Pdb) list
      1     def f(x):   
      2  ->     g(x*2)  
    [EOF]
    (Pdb) next
    --Return--
    > <doctest foo-bar@baz[2]>(1)<module>()->None
    -> f(3)
    (Pdb) list
      1  -> f(3)
    [EOF]
    (Pdb) continue
    **********************************************************************
    File "foo-bar@baz.py", line 7, in foo-bar@baz
    Failed example:
        f(3)
    Expected nothing
    Got:
        9
    TestResults(failed=1, attempted=3)
Got:
    (Pdb) step
    --Return--
    > <doctest foo-bar@baz[1]>(3)g()->None
    -> import pdb; pdb.set_trace()
    (Pdb) list
      1         def g(x):
      2             print(x+3)
      3  ->         import pdb; pdb.set_trace()
    [EOF]
    (Pdb) next
    --Return--
    > <doctest foo-bar@baz[0]>(2)f()->None
    -> g(x*2)
    (Pdb) list
      1         def f(x):
      2  ->         g(x*2)
    [EOF]
    (Pdb) next
    --Return--
    > <doctest foo-bar@baz[2]>(1)<module>()->None
    -> f(3)
    (Pdb) list
      1  ->     f(3)
    [EOF]
    (Pdb) continue
    **********************************************************************
    File "foo-bar@baz.py", line 7, in foo-bar@baz
    Failed example:
        f(3)
    Expected nothing
    Got:
        9
    TestResults(failed=1, attempted=3)


======================================================================
FAIL: test_pdb_set_trace_nested (test.test_doctest.test_doctest)
Doctest: test.test_doctest.test_doctest.test_pdb_set_trace_nested
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sk/src/cpython/Lib/doctest.py", line 2327, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for test.test_doctest.test_doctest.test_pdb_set_trace_nested
  File "/home/sk/src/cpython/Lib/test/test_doctest/test_doctest.py", line 2165, in test_pdb_set_trace_nested

----------------------------------------------------------------------
File "/home/sk/src/cpython/Lib/test/test_doctest/test_doctest.py", line 2202, in test.test_doctest.test_doctest.test_pdb_set_trace_neste
d
Failed example:
    try:
        runner.run(test)
    finally:
        sys.stdin = real_stdin
    # doctest: +REPORT_NDIFF
Differences (ndiff with -expected +actual):
    - > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(4)calls_set_trace()
    - -> import pdb; pdb.set_trace()
      (Pdb) step
      > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(5)calls_set_trace()
      -> self.f1()
      (Pdb) print(y)
      1
      (Pdb) step
      --Call--
      > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(7)f1()
      -> def f1(self):
      (Pdb) step
      > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(8)f1()
      -> x = 1
      (Pdb) step
      > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(9)f1()
      -> self.f2()
      (Pdb) step
      --Call--
      > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(11)f2()
      -> def f2(self):
      (Pdb) step
      > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(12)f2()
      -> z = 1
      (Pdb) step
      > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(13)f2()
      -> z = 2
      (Pdb) print(z)
      1
      (Pdb) up
      > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(9)f1()
      -> self.f2()
      (Pdb) print(x)
      1
      (Pdb) up
      > <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(5)calls_set_trace()
      -> self.f1()
      (Pdb) print(y)
      1
      (Pdb) up
      > <doctest foo-bar@baz[1]>(1)<module>()
      -> calls_set_trace()
      (Pdb) print(foo)  
      *** NameError: name 'foo' is not defined
      (Pdb) continue
      TestResults(failed=0, attempted=2)


----------------------------------------------------------------------
Ran 69 tests in 4.415s  

FAILED (failures=3)
test test_doctest failed
test_doctest failed (3 failures)

== Tests result: FAILURE ==

1 test failed:
    test_doctest

Total duration: 5.4 sec 
Total tests: run=69 failures=3
Total test files: run=1/1 failed=1
Result: FAILURE

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Activity

  1. picnixz commented on Jun 5, 2024

    @picnixz
    Member

    It appears that the first lines until the first actual usage of pdb are never printed. Have you perhaps changed some lines / used an incorrect branch / not up-to-date branch?

    EDIT: I cannot reproduce by the way (forgot to mention it). I'm on OpenSUSE 15.5.

  2. sobolevn commented on Jun 5, 2024

    @sobolevn
    Member

    I cannot reproduce it on macos

  3. skirpichev commented on Jun 5, 2024

    @skirpichev
    MemberAuthor

    used an incorrect branch / not up-to-date branch?

    Well, first that happened not on the master^Wmain. But I did update (you can see my fork) and I run git clean -Xdf.

  4. picnixz commented on Jun 5, 2024

    @picnixz
    Member

    Err... maybe it's a coincidence, but is your branch with those issues the #108562, namely the PR #116346? (you mentioned 108562 so I think it's the corresponding issue?). If so, I don't think it's up-to-date. If not, which branch are you working on?

  5. skirpichev commented on Jun 6, 2024

    @skirpichev
    MemberAuthor

    but is your branch with those issues the #108562

    These warnings exist on in the main.

    If not, which branch are you working on?

    The main.

    Ok, as I expected, this happens due to local configuration:

    $ cat ~/.pdbrc 
    alias pp from diofant import pprint;; pprint(%1)
    

    I'll update description.

    Can you reproduce issue with:

    $ cat ~/.pdbrc
    alias si from cmath import sin;; sin(%1)
    

    ?

  6. changed the title [-]Failures in test_doctest[/-] [+]Failures in test_doctest (due to nonempty .pdbrc)[/+] on Jun 6, 2024
  7. skirpichev commented on Jun 6, 2024

    @skirpichev
    MemberAuthor

    9c93350 - no errors; I'll try to bisect.

  8. skirpichev commented on Jun 6, 2024

    @skirpichev
    MemberAuthor

    Bisected to 44f9a84

    CC @gaogaotiantian

  9. gaogaotiantian commented on Jun 6, 2024

    @gaogaotiantian
    Member

    This is a known issue #119824 and the fix is in #119882. It's still under review and will be backported.

  10. skirpichev commented on Jun 6, 2024

    @skirpichev
    MemberAuthor

    Ok, sorry for a duplicate.

  11. picnixz commented on Jun 6, 2024

    @picnixz
    Member

    Ok, as I expected, this happens due to local configuration:

    Oh, I actually dismissed this one because I thought that .pdbrc would not have been read at all because of readrc=False but it appears not.

  12. gaogaotiantian commented on Jun 6, 2024

    @gaogaotiantian
    Member

    Ok, sorry for a duplicate.

    There's no need to be sorry :) You did a great job linking the issue together so we can solve them both when the PR is merged.

  13. gaogaotiantian commented on Jun 6, 2024

    @gaogaotiantian
    Member

    Oh, I actually dismissed this one because I thought that .pdbrc would not have been read at all because of readrc=False but it appears not.

    .pdbrc should not be read when readrc=False. Where was it set to False? pdb.set_trace() will not set readrc to False.

  14. picnixz commented on Jun 6, 2024

    @picnixz
    Member

    Ah my bad! I actually looked at the incorrect doctest file. Actually in test_pdb, there are some readrc=False calls (which I thought were the culprits) but not in the test_doctest file! So, maybe just adding those readrc=False for the tests in test_doctest would be fine?

  15. skirpichev commented on Jun 6, 2024

    @skirpichev
    MemberAuthor

    Hmm, maybe it's a good idea to permit readrc argument here and use that in test_doctest/* to isolate from local environment?

  16. gaogaotiantian commented on Jun 6, 2024

    @gaogaotiantian
    Member

    readrc is only available to the pdb.Pdb class now. pdb.set_trace() can't do that. We can propose something but that would be a new feature to pdb.

  17. skirpichev commented on Jun 25, 2024

    @skirpichev
    MemberAuthor

    #119882 was merged and it seems this is fixed.

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

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions