Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Readline-reliant tests are not isolated from personal init files #142353

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixestestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error
@johnslavik

Description

@johnslavik

Bug description

This example test uses\x08 to simulate backspace:

deftest_multiline_auto_indent(self):
script=textwrap.dedent("""
import pdb; pdb.Pdb().set_trace()
""")
input=b"def f(x):\n"
input+=b"if x > 0:\n"
input+=b"x += 1\n"
input+=b"return x\n"
# We need to do backspaces to remove the auto-indentation
input+=b"\x08\x08\x08\x08else:\n"
input+=b"return -x\n"
input+=b"\n"
input+=b"f(-21-21)\n"
input+=b"c\n"
output=run_pty(script,input)
self.assertIn(b'42',output)

With a GNU readline backend (e.g. on Linux), somebody's~/.inputrc could break this heuristic and cause the test to fail.

To reproduce:

# remap \x08echo'"\C-h": backward-kill-word'>|${TMP_INPUTRC:=$(mktemp)}# run testINPUTRC=$TMP_INPUTRC ./python -mtest test_pdb -m test_multiline_auto_indent# cleanuprm -fv$TMP_INPUTRC
======================================================================FAIL: test_multiline_auto_indent (Lib.test.test_pdb.PdbTestReadline.test_multiline_auto_indent)----------------------------------------------------------------------Traceback (most recent call last):  File "/home/bswck/Python/cpython/Lib/test/test_pdb.py", line 4991, in test_multiline_auto_indent    self.assertIn(b'42', output)    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^AssertionError: b'42' not found in bytearray(b"def f(x):\r\nif x > 0:\r\nx += 1\r\nreturn x\r\n^H^H^H^Helse:\r\nreturn -x\r\n\r\nf(-21-21)\r\nc\r\n> <string>(2)<module>()\r\n(Pdb) def f(x):\r\n...       if x > 0:\r\n...           x += 1\r\n...           return x\r\n...           \r\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[Kelse:\r\n*** SyntaxError: invalid syntax\r\n(Pdb) return -x\r\n*** Invalid argument: -x\r\n      Usage: r(eturn)\r\n(Pdb) \r\n*** Invalid argument: -x\r\n      Usage: r(eturn)\r\n(Pdb) f(-21-21)\r\n*** NameError: name 'f' is not defined\r\n(Pdb) c\r\n")----------------------------------------------------------------------Ran 1 test in 0.244sFAILED (failures=1)removed '/tmp/tmp.VXGud3AbMo'

IfINPUTRC (orEDITRC if libedit is used1) points to a clean file, the default Readline keybinds in tests always work:

❯ INPUTRC=/dev/null ./python -m test test_pdb -m test_multiline_auto_indentUsing random seed: 40484174290:00:00 load avg: 0.81 Run 1 test sequentially in a single process0:00:00 load avg: 0.81 [1/1] test_pdb0:00:00 load avg: 0.81 [1/1] test_pdb passed== Tests result: SUCCESS ==1 test OK.Total duration: 509 msTotal tests: run=1 (filtered)Total test files: run=1/1 (filtered)Result: SUCCESS

Scope

This issue is relevant to PTY tests only:

  • input() uses readline only if stdin a TTY
  • code.InteractiveConsole usesinput() in general
  • pdb interactive mode isn't tested outside of PTY
  • the new REPL requires stdin to be a TTY (because it emulates readline), falls back to basic REPL otherwise
  • the basic REPL doesn't use readline

Resolution

To avoid looking into$HOME/.inputrc or/etc/inputrc (or$PWD/.editrc or$HOME/.editrc1) which can cause test pollution, we could ensure thatINPUTRC (andEDITRC?1) environment variablesare set to a path of an empty file in the proper test setup code.

The most tempting idea I have is to add a flag parameter likereadline= torun_pty() that would create the proper environment dict ifenv isNone.

CC@ZeroIntensity (mentorship)type-bug,tests,3.13,3.14,3.15

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Footnotes

  1. I have not confirmed these libedit specifics -- only found them. I couldn't find any documentation onEDITRC anywhere.23

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixestestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp