Skip to content

test_pyrepl may read its own output #121603

@colesbury

Description

@colesbury

First, a caveat: I don't understand psuedo-terminals well and I'm fairly confused by this.

When process start-up is slow (such as under heavy load), the pyrepl tests that use test_pyrepl.run_repl may read their own command as output. Data that is written to master_fd is immediately available to be read from mater_fd, so if the subprocess is not quick enough at reading the input.

master_fd, slave_fd = pty.openpty()

os.write(master_fd, repl_input.encode("utf-8"))
output = []
while select.select([master_fd], [], [], 0.5)[0]:
data = os.read(master_fd, 1024).decode("utf-8")

This leads to test errors that look like:

FAIL: test_python_basic_repl (test.test_pyrepl.test_pyrepl.TestMain.test_python_basic_repl)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/raid/sgross/cpython/Lib/test/support/__init__.py", line 2622, in wrapper
    return func(*args, **kwargs)
  File "/raid/sgross/cpython/Lib/test/test_pyrepl/test_pyrepl.py", line 892, in test_python_basic_repl
    self.assertIn("True", output)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
AssertionError: 'True' not found in 'from test.support import initialized_with_pyrepl\r\ninitialized_with_pyrepl()\r\nexit()\r\n'

In other words, the parent is seeing its own command as if its the output from the subprocess.

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtopic-replRelated to the interactive shell

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions