Skip to content
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

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

Closed
skirpichev opened this issue Jun 5, 2024 · 16 comments
Closed

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

skirpichev opened this issue Jun 5, 2024 · 16 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@skirpichev
Copy link
Member

skirpichev commented Jun 5, 2024

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

@skirpichev skirpichev added the type-bug An unexpected behavior, bug, or error label Jun 5, 2024
@picnixz
Copy link
Contributor

picnixz commented Jun 5, 2024

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.

@sobolevn
Copy link
Member

sobolevn commented Jun 5, 2024

I cannot reproduce it on macos

@skirpichev
Copy link
Member Author

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.

@picnixz
Copy link
Contributor

picnixz commented Jun 5, 2024

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?

@skirpichev
Copy link
Member Author

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)

?

@skirpichev skirpichev changed the title Failures in test_doctest Failures in test_doctest (due to nonempty .pdbrc) Jun 6, 2024
@skirpichev
Copy link
Member Author

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

@skirpichev
Copy link
Member Author

Bisected to 44f9a84

CC @gaogaotiantian

@gaogaotiantian
Copy link
Member

gaogaotiantian commented Jun 6, 2024

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

@skirpichev
Copy link
Member Author

Ok, sorry for a duplicate.

@picnixz
Copy link
Contributor

picnixz commented Jun 6, 2024

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.

@gaogaotiantian
Copy link
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.

@gaogaotiantian
Copy link
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.

@picnixz
Copy link
Contributor

picnixz commented Jun 6, 2024

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?

@skirpichev
Copy link
Member Author

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

@gaogaotiantian
Copy link
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.

@skirpichev
Copy link
Member Author

#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
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants