This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_builtin: PtyTests fail when run twice
Type: Stage: resolved
Components: Tests Versions: Python 3.10
process
Status: closed Resolution: duplicate
Dependencies: Superseder: test_builtin.PtyTests fail on non-ASCII characters if the readline module is loaded
View: 13886
Assigned To: Nosy List: shihai1991, vstinner
Priority: normal Keywords:

Created on 2020-06-19 10:22 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (7)
msg371871 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-19 10:22
I tried to check for reference leaks, but running test_builtin twice fails:

$ ./python -m test -R 3:3 test_builtin 
0:00:00 load avg: 2.18 Run tests sequentially
0:00:00 load avg: 2.18 [1/1] test_builtin
beginning 6 repetitions
123456
.test test_builtin failed -- multiple errors occurred; run in verbose mode for details
test_builtin failed

== Tests result: FAILURE ==

1 test failed:
    test_builtin

Total duration: 1.3 sec
Tests result: FAILURE



The error comes from PtyTests, but the issue is only triggered when builtins.float.hex is also run:

$ ./python -m test test_builtin test_builtin -m test.test_builtin.PtyTests.test_input_tty_non_ascii_unicode_errors -m builtins.float.hex   -v
== CPython 3.10.0a0 (heads/master:310f6aa7db, Jun 19 2020, 12:18:54) [GCC 10.1.1 20200507 (Red Hat 10.1.1-1)]
== Linux-5.6.18-300.fc32.x86_64-x86_64-with-glibc2.31 little-endian
== cwd: /home/vstinner/python/master/build/test_python_122646
== CPU count: 8
== encodings: locale=UTF-8, FS=utf-8
0:00:00 load avg: 0.60 Run tests sequentially
0:00:00 load avg: 0.60 [1/2] test_builtin
test_input_tty_non_ascii_unicode_errors (test.test_builtin.PtyTests) ... ok
hex (builtins.float)
Doctest: builtins.float.hex ... ok

----------------------------------------------------------------------

Ran 2 tests in 0.009s

OK
0:00:00 load avg: 0.63 [2/2] test_builtin
test_input_tty_non_ascii_unicode_errors (test.test_builtin.PtyTests) ... FAIL
hex (builtins.float)
Doctest: builtins.float.hex ... ok

======================================================================
FAIL: test_input_tty_non_ascii_unicode_errors (test.test_builtin.PtyTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2105, in test_input_tty_non_ascii_unicode_errors
    self.check_input_tty("prompté", b"quux\xe9", "ascii")
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2092, in check_input_tty
    self.assertEqual(input_result, expected)
AssertionError: 'quux' != 'quux\udce9'
- quux
+ quux\udce9
?     +


----------------------------------------------------------------------

Ran 2 tests in 0.011s

FAILED (failures=1)
test test_builtin failed
test_builtin failed

== Tests result: FAILURE ==

1 test OK.

1 test failed:
    test_builtin

Total duration: 762 ms
Tests result: FAILURE
msg371872 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-19 10:36
test_input_tty_non_ascii_unicode_errors() fails if readline was imported previously. Example:

$ ./python -m test test_readline test_builtin -v 
(...)
======================================================================
FAIL: test_input_tty_non_ascii (test.test_builtin.PtyTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2102, in test_input_tty_non_ascii
    self.check_input_tty("prompté", b"quux\xe9", "utf-8")
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2093, in check_input_tty
    self.assertEqual(input_result, expected)
AssertionError: 'quux' != 'quux\udce9'
- quux
+ quux\udce9
?     +


======================================================================
FAIL: test_input_tty_non_ascii_unicode_errors (test.test_builtin.PtyTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2106, in test_input_tty_non_ascii_unicode_errors
    self.check_input_tty("prompté", b"quux\xe9", "ascii")
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2093, in check_input_tty
    self.assertEqual(input_result, expected)
AssertionError: 'quux' != 'quux\udce9'
- quux
+ quux\udce9
?     +



Another example: import readline in test_builtin.

diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 40df7b606a..102b397e66 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1,3 +1,4 @@
+import readline
 # Python test set -- built-in functions
 
 import ast


$ ./python -m test test_builtin -v -m PtyTests
== CPython 3.10.0a0 (heads/master:310f6aa7db, Jun 19 2020, 12:18:54) [GCC 10.1.1 20200507 (Red Hat 10.1.1-1)]
== Linux-5.6.18-300.fc32.x86_64-x86_64-with-glibc2.31 little-endian
== cwd: /home/vstinner/python/master/build/test_python_123487
== CPU count: 8
== encodings: locale=UTF-8, FS=utf-8
0:00:00 load avg: 0.36 Run tests sequentially
0:00:00 load avg: 0.36 [1/1] test_builtin
test_input_no_stdout_fileno (test.test_builtin.PtyTests) ... ok
test_input_tty (test.test_builtin.PtyTests) ... ok
test_input_tty_non_ascii (test.test_builtin.PtyTests) ... FAIL
test_input_tty_non_ascii_unicode_errors (test.test_builtin.PtyTests) ... FAIL

======================================================================
FAIL: test_input_tty_non_ascii (test.test_builtin.PtyTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2102, in test_input_tty_non_ascii
    self.check_input_tty("prompté", b"quux\xe9", "utf-8")
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2093, in check_input_tty
    self.assertEqual(input_result, expected)
AssertionError: 'quux' != 'quux\udce9'
- quux
+ quux\udce9
?     +


======================================================================
FAIL: test_input_tty_non_ascii_unicode_errors (test.test_builtin.PtyTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2106, in test_input_tty_non_ascii_unicode_errors
    self.check_input_tty("prompté", b"quux\xe9", "ascii")
  File "/home/vstinner/python/master/Lib/test/test_builtin.py", line 2093, in check_input_tty
    self.assertEqual(input_result, expected)
AssertionError: 'quux' != 'quux\udce9'
- quux
+ quux\udce9
?     +


----------------------------------------------------------------------

Ran 4 tests in 0.028s

FAILED (failures=2)
test test_builtin failed
test_builtin failed

== Tests result: FAILURE ==

1 test failed:
    test_builtin

Total duration: 446 ms
Tests result: FAILURE
msg371873 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-19 10:38
The two non-ASCII tests are very old:

commit 0d776b1ce849ff0646738b6361ef940ab6f8b9cb
Author: Antoine Pitrou <solipsis@pitrou.net>
Date:   Sun Nov 6 00:34:26 2011 +0100

    Issue #13342: input() used to ignore sys.stdin's and sys.stdout's unicode
    error handler in interactive mode (when calling into PyOS_Readline()).


The code was refactored later by:

commit c9a6ab56cfae90c96c1361314c3c99b32e114446
Author: Martin Panter <vadmium+py@gmail.com>
Date:   Sat Oct 10 01:25:38 2015 +0000

    Issue #24402: Fix input() when stdout.fileno() fails; diagnosed by Eryksun
    
    Also factored out some test cases into a new PtyTests class.
msg371874 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-19 10:39
I reproduce the issue on Fedora 32 with readline 8.0:

$ ./python -m test.pythoninfo|grep readline
readline._READLINE_LIBRARY_VERSION: 8.0
readline._READLINE_RUNTIME_VERSION: 0x800
readline._READLINE_VERSION: 0x800
msg371875 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-19 10:41
I also reproduce the issue on RHEL 8 with readline 7.0.

But the issue is hidden if stdout is not a TTY. I use "| cat", so Python stdout is a pipe:

$ ./python -m test test_readline test_builtin -v|cat
(...)
Tests result: SUCCESS
msg371877 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-19 10:44
See also:

* bpo-19884: "Importing readline produces erroneous output". Worked around using TERM='xterm-256color env var and by calling rl_variable_bind ("enable-meta-key", "off");
* bpo-11679 "readline interferes with characters beginning with byte \xe9".
msg410771 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-01-17 12:33
The "./python -m test -R 3:3 test_builtin" command loads the readline module somehow:
---
$ ./python -i -m test -R 3:3 test_builtin 
(...)
SystemExit: 0

>>> import sys
>>> 'readline' in sys.modules
True
---

This bug is a duplicate of bpo-13886. Moreover, I tested manually: my change GH-30631 fix this issue.
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85206
2022-01-17 12:33:21vstinnersetstatus: open -> closed
superseder: test_builtin.PtyTests fail on non-ASCII characters if the readline module is loaded
messages: + msg410771

resolution: duplicate
stage: resolved
2020-06-19 15:46:38shihai1991setnosy: + shihai1991
2020-06-19 10:44:56vstinnersetmessages: + msg371877
2020-06-19 10:41:38vstinnersetmessages: + msg371875
2020-06-19 10:39:21vstinnersetmessages: + msg371874
2020-06-19 10:38:42vstinnersetmessages: + msg371873
2020-06-19 10:36:51vstinnersetmessages: + msg371872
2020-06-19 10:22:34vstinnercreate