Skip to content

test_pyrepl.test_no_newline() failure on main #143394

Closed

Description

@smontanaro

Bug report

Bug description:

test_pyrepl started failing for me a day or two ago. According to git bisect, this is the problematic commit:

8a2deea1fc725f8147254f87c6042fcf75a1d03b is the first bad commit
commit 8a2deea1fc725f8147254f87c6042fcf75a1d03b
Author: Jan-Eric Nitschke <47750513+JanEricNitschke@users.noreply.github.com>
Date:   Fri Jan 2 14:04:37 2026 +0100

    gh-128067: Fix pyrepl overriding printed output without newlines (#138732)
    
    Co-authored-by: Łukasz Langa <lukasz@langa.pl>

 Lib/_pyrepl/unix_console.py                                        |  7 +++---
 Lib/_pyrepl/windows_console.py                                     |  7 +++---
 Lib/test/test_pyrepl/test_pyrepl.py                                | 38 +++++++++++++++++++++++++++++++
 Lib/test/test_pyrepl/test_unix_console.py                          | 14 ++++++++++++
 Lib/test/test_pyrepl/test_windows_console.py                       | 14 ++++++++++++
 Misc/ACKS                                                          |  1 +
 .../next/Windows/2025-09-14-13-35-44.gh-issue-128067.BGdP_A.rst    |  1 +
 7 files changed, 76 insertions(+), 6 deletions(-)
 create mode 100644 Misc/NEWS.d/next/Windows/2025-09-14-13-35-44.gh-issue-128067.BGdP_A.rst

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. johnslavik commented on Jan 3, 2026

    @johnslavik
    Member

    What are the failures you're seeing exactly? Which tests are failing exactly? @ZeroIntensity topic-repl pending (I'd skip any other labels because we don't have enough information)

  2. smontanaro commented on Jan 3, 2026

    @smontanaro
    ContributorAuthor

    Sorry, forgot the key bit.

    ======================================================================
    FAIL: test_no_newline (test.test_pyrepl.test_pyrepl.TestMain.test_no_newline)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/skip/src/python/cpython/Lib/test/support/__init__.py", line 3022, in wrapper
        return func(*args, **kwargs)
      File "/Users/skip/src/python/cpython/Lib/test/test_pyrepl/test_pyrepl.py", line 1909, in test_no_newline
        self.assertIn(expected_output_sequence, cleaned_output)
        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: 'Something pretty long>>> exit()' not found in 'print(\'Something pretty long\', end=\'\')\r\nexit()\r\nPython 3.15.0a3+ free-threading build (bisect/good-18f3c59e57e5d30218210136060310310b10ff72-2-g09ce5924996:09ce5924996,) [Clang 21.1.8 ] on darwin\r\nType "help", "copyright", "credits" or "license" for more information.\r\n\x1b[?7l>>> print(\'Something pretty long\', end=\'\')\x1b[42D\n\r\x1b[?7hSomething pretty long\x1b[?7l>>> exit()\x1b[10D\n\r\x1b[?7h'
    
  3. johnslavik commented on Jan 3, 2026

    @johnslavik
    Member

    Notes: cleaned_output contained unexpected ANSI sequences, free-threaded build (unlikely to be related).

  4. smontanaro commented on Jan 3, 2026

    @smontanaro
    ContributorAuthor

    Failing on 3.14 branch as well.

    ======================================================================
    FAIL: test_no_newline (test.test_pyrepl.test_pyrepl.TestMain.test_no_newline)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/skip/src/python/py3.14/Lib/test/support/__init__.py", line 2935, in wrapper
        return func(*args, **kwargs)
      File "/Users/skip/src/python/py3.14/Lib/test/test_pyrepl/test_pyrepl.py", line 1899, in test_no_newline
        self.assertIn(expected_output_sequence, cleaned_output)
        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: 'Something pretty long>>> exit()' not found in 'print(\'Something pretty long\', end=\'\')\r\nexit()\r\nPython 3.14.2+ free-threading build (heads/3.14:6583951e7de, Dec 29 2025, 09:10:49) [Clang 21.1.8 ] on darwin\r\nType "help", "copyright", "credits" or "license" for more information.\r\n\x1b[?7l>>> print(\'Something pretty long\', end=\'\')\x1b[42D\n\r\x1b[?7hSomething pretty long\x1b[?7l>>> exit()\x1b[10D\n\r\x1b[?7h'
    
  5. johnslavik commented on Jan 3, 2026

    @johnslavik
    Member

    For the passing case, cleaned_output ends with

    Something pretty long>>> exit()\x1b[10D\n\r
    

    For the OP's case, cleaned_output ends with

    Something pretty long\x1b[?7l>>> exit()\x1b[10D\n\r\x1b[?7h
    

    The presence of \x1b[?7l prevented the test from passing.

  6. johnslavik commented on Jan 3, 2026

    @johnslavik
    Member

    As noted, this is related to GH-138732. CC @JanEricNitschke @chris-eibl

    @ambv, this looks similar to the builbot failure from GH-138732 where \x1b[34h popped up. However, this issue appeared on MacOS and the sequence was \x1b[?7l.

    Not sure whether this is tests or stdlib -- auto-wrap mode from ?7h and ?7l may technically change the visual output and cursor position. Please confirm me on that though.

    @ZeroIntensity 3.13 3.14 3.15 (and topic-repl of course)

  7. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Jan 3, 2026
  8. added
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Jan 3, 2026
  9. chris-eibl commented on Jan 4, 2026

    @chris-eibl
    Member

    test_no_newline needs a lot of filtering, and that's why I suggested two easier tests additionally. Łukasz already hardened test_no_newline in #143356.

    We can try to filter for \x1b[?7l as well, but if test_no_newline gets a maintenance burden, IMHO we can just remove it, too?

  10. chris-eibl commented on Jan 4, 2026

    @chris-eibl
    Member

    @smontanaro does adding

    safe_patterns.append(r'\x1b[?7l')  # auto wrap
    

    fix the issue for you?

  11. johnslavik commented on Jan 4, 2026

    @johnslavik
    Member

    If that's the case, let's relabel this as tests @picnixz (not stdlib)

  12. 24 remaining items

  13. added 2 commits that reference this issue on Feb 15, 2026
  14. furkanonder commented on Mar 29, 2026

    @furkanonder
    Contributor

    The test is only passing when the GNU readline is enabled in the CPython build.

    Why readline matters

    The test sends both commands at once via os.write(master_fd, b"print('Something pretty long', end='')\nexit()\n") to a PTY master.

    • With readline: readline puts the terminal in raw mode (ECHO=off) because it handles character echoing itself.
      With kernel ECHO disabled, input written to the PTY master is not echoed back into the read stream. The output
      is clean – just the REPL's own output - and "Something pretty long>>> exit()" is found.

    • Without readline: the basic REPL falls back to plain C fgets(), which doesn't touch terminal settings. The
      kernel's ECHO flag stays on, so every byte written to the PTY master is immediately echoed back into the read stream.
      Both commands (print(…)\r\nexit()\r\n) are echoed as a block before the REPL processes anything. exit() appears
      early in this echo block, never after >>>, and the assertion fails.

    How I confirmed this

    I wrote a diagnostic script debug_pyrepl_issue.py that checks whether the REPL toggles the ECHO termios flag (indicating readline is active) and then reproduces the test scenario.

    Example output on a machine without readline:

    $ ./python debug_pyrepl_issue.py
    Python: ./python
    Platform: FreeBSD 14.1-RELEASE-p4 amd64
    Version: 3.15.0a7+
    
    --- Phase 1: detect readline ---
    Initial:  ECHO=True  ICANON=True
    At prompt: ECHO=True  ICANON=True
    ECHO unchanged (readline NOT active)
    
    --- Phase 2: reproduce test_no_newline ---
    Test assertion: FAIL ('Something pretty long>>> exit()' NOT found)
    result='print(\'Something pretty long\', end=\'\')\r\nexit()\r\nPython 3.15.0a5+ (heads/main:979d92fefc0, Jan 25 2026, 06:54:33) [GCC 14.2.0] on linux\r\nType "help", "copyright", "credits" or "license" for more information.\r\n>>> Something pretty long>>> '
    
    readline MISSING -> ECHO on -> echo pollution -> test FAILS

    Example output on a machine with readline:

    $ ./python debug_pyrepl_issue.py 
    Python: /home/arf/Desktop/cpython-pyrepl-issue/python
    Platform: Linux 6.18.20-1-lts x86_64
    Version: 3.15.0a5+ (heads/main:979d92fefc, Jan 25 2026, 16:09:18) [GCC 15.2.1 20260103]
    
    --- Phase 1: detect readline ---
    Initial:  ECHO=True  ICANON=True
    At prompt: ECHO=False  ICANON=False
    ECHO changed: True -> False (readline is active)
    
    --- Phase 2: reproduce test_no_newline ---
    Test assertion: PASS ('Something pretty long>>> exit()' found)
    
    readline present -> ECHO off -> clean output -> test PASSES

    This is directly visible in the buildbot configure logs:

  15. vstinner commented on Apr 1, 2026

    @vstinner
    Member

    On Linux, I confirm that test_pyrepl pass with the readline module, and fails without the readline module (ex: run find -name "readline*so" -delete in the Python source tree).

  16. added a commit that references this issue on Apr 1, 2026
  17. vstinner commented on Apr 1, 2026

    @vstinner
    Member

    I wrote #147973 to skip the test on the basic REPL if the readline module is missing.

  18. added a commit that references this issue on Apr 2, 2026
  19. added 2 commits that reference this issue on Apr 2, 2026
  20. vstinner commented on Apr 2, 2026

    @vstinner
    Member

    The latest known test_no_newline() failure should be fixed by 97babb8 (backport to 3.13 and 3.14 will follow once the CI pass on the PRs). I close the issue.

  21. added a commit that references this issue on Apr 3, 2026
  22. smontanaro commented on Apr 3, 2026

    @smontanaro
    ContributorAuthor

    Thanks @vstinner. Fixed for me, even on my very pokey Raspberry Pi (which I only test on "for fun").

  23. added a commit that references this issue on Apr 4, 2026
  24. added a commit that references this issue on Apr 25, 2026
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.13only security fixes3.14bugs and security fixes3.15bugs and security fixestestsTests in the Lib/test dirtopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions