cpython icon indicating copy to clipboard operation
cpython copied to clipboard

test_pyrepl failure on main

Open smontanaro opened this issue 1 month ago • 10 comments

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 <[email protected]>
Date:   Fri Jan 2 14:04:37 2026 +0100

    gh-128067: Fix pyrepl overriding printed output without newlines (#138732)
    
    Co-authored-by: Łukasz Langa <[email protected]>

 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

  • gh-143433
  • gh-143459
  • gh-143461

smontanaro avatar Jan 03 '26 20:01 smontanaro

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)~~

johnslavik avatar Jan 03 '26 21:01 johnslavik

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'

smontanaro avatar Jan 03 '26 21:01 smontanaro

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

johnslavik avatar Jan 03 '26 21:01 johnslavik

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'

smontanaro avatar Jan 03 '26 21:01 smontanaro

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.

johnslavik avatar Jan 03 '26 21:01 johnslavik

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)

johnslavik avatar Jan 03 '26 21:01 johnslavik

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 https://github.com/python/cpython/pull/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?

chris-eibl avatar Jan 04 '26 07:01 chris-eibl

@smontanaro does adding

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

fix the issue for you?

chris-eibl avatar Jan 04 '26 07:01 chris-eibl

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

johnslavik avatar Jan 04 '26 11:01 johnslavik

@smontanaro does adding

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

fix the issue for you?

After adding a couple more backslashes, yes.

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

smontanaro avatar Jan 04 '26 17:01 smontanaro

Seems to be working for me on main and 3.14.

smontanaro avatar Jan 06 '26 13:01 smontanaro

Still fails on 3.13. Awaiting backport? My repo is up-to-date.

% ./python.exe -m test -uall test_pyrepl
Using random seed: 3581558757
0:00:00 load avg: 3.09 Run 1 test sequentially in a single process
0:00:00 load avg: 3.09 [1/1] test_pyrepl
test test_pyrepl failed -- Traceback (most recent call last):
  File "/Users/skip/src/python/py3.13/Lib/test/support/__init__.py", line 2780, in wrapper
    return func(*args, **kwargs)
  File "/Users/skip/src/python/py3.13/Lib/test/test_pyrepl/test_pyrepl.py", line 1475, 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.13.11+ (heads/3.13:f2665b6ac25, Jan  6 2026, 07:05:22) [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'

0:00:12 load avg: 2.62 [1/1/1] test_pyrepl failed (1 failure)

smontanaro avatar Jan 06 '26 13:01 smontanaro

Still fails on 3.13. Awaiting backport? My repo is up-to-date.

Wasn't backported, yet. I've kicked off the backport to 3.13.

chris-eibl avatar Jan 06 '26 13:01 chris-eibl

All fixed, thanks for your report, Skip.

ambv avatar Jan 06 '26 18:01 ambv

Maybe I shouldn't reopen this, but I seem to be having the same problem on my old Dell laptop. The environment is Ubuntu Budgie 25.10 (just upgraded). I ssh'd into it from an Apple Terminal, updated my repo (just main), cleaned and rebuilt. test_pyrepl fails in what seems to be a similar/identical way to the failure I saw on my Mac.

$ ./python -m test test_cppext test_pyrepl test_venv
Using random seed: 3634603286
0:00:00 load avg: 0.21 Run 3 tests sequentially in a single process
0:00:00 load avg: 0.21 [1/3] test_cppext
0:00:00 load avg: 0.21 [1/3] test_cppext passed
0:00:00 load avg: 0.21 [2/3] test_pyrepl
test test_pyrepl failed -- Traceback (most recent call last):
  File "/home/skip/src/python/cpython/Lib/test/support/__init__.py", line 3033, in wrapper
    return func(*args, **kwargs)
  File "/home/skip/src/python/cpython/Lib/test/test_pyrepl/test_pyrepl.py", line 1952, in test_no_newline
    self.assertIn(expected_output_sequence, basic_output)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'Something pretty long>>> exit()' not found in 'print(\'Something pretty long\', end=\'\')\r\nexit()\r\nPython 3.15.0a3+ (heads/main:e2f15aec164, Jan  8 2026, 14:08:20) [Clang 20.1.8 (0ubuntu4)] on linux\r\nType "help", "copyright", "credits" or "license" for more information.\r\n>>> Something pretty long>>> '

0:00:03 load avg: 0.28 [2/3/1] test_pyrepl failed (1 failure)
0:00:03 load avg: 0.28 [3/3/1] test_venv
Could not find platform dependent libraries <exec_prefix>
0:00:06 load avg: 0.28 [3/3/1] test_venv passed

== Tests result: FAILURE ==

1 test failed:
    test_pyrepl

Okay, maybe that's some weird side effect of using Apple's Terminal app:

$ env | grep TERM
TERM=xterm-256color

I then logged in on the console, opened an Xfce terminal and tried again. Still fails in the same way. In the example below, I overrode TERM, but leaving it set to xterm-256color yields the same output.

$ env | grep TERM
COLORTERM=truecolor
TERM=xterm-256color
$ TERM=xterm ./python -m test test_pyrepl
Using random seed: 2331405634
0:00:00 load avg: 0.53 Run 1 test sequentially in a single process
0:00:00 load avg: 0.53 [1/1] test_pyrepl
test test_pyrepl failed -- Traceback (most recent call last):
  File "/home/skip/src/python/cpython/Lib/test/support/__init__.py", line 3033, in wrapper
    return func(*args, **kwargs)
  File "/home/skip/src/python/cpython/Lib/test/test_pyrepl/test_pyrepl.py", line 1952, in test_no_newline
    self.assertIn(expected_output_sequence, basic_output)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'Something pretty long>>> exit()' not found in 'print(\'Something pretty long\', end=\'\')\r\nexit()\r\nPython 3.15.0a3+ (heads/main:e2f15aec164, Jan  8 2026, 14:08:20) [Clang 20.1.8 (0ubuntu4)] on linux\r\nType "help", "copyright", "credits" or "license" for more information.\r\n>>> Something pretty long>>> '

0:00:03 load avg: 0.53 [1/1/1] test_pyrepl failed (1 failure)

== Tests result: FAILURE ==

1 test failed:
    test_pyrepl

smontanaro avatar Jan 08 '26 20:01 smontanaro

@chris-eibl @ambv I can't reopen the ticket. Your call...

smontanaro avatar Jan 08 '26 20:01 smontanaro

Seems this time exit() is missing at the end of the output >>> Something pretty long>>> ', but I don't know why, yet.

chris-eibl avatar Jan 09 '26 06:01 chris-eibl