Skip to content

test_repl.test_toplevel_contextvars_async fails under Fish in a VS Code terminal #137569

Closed

Description

@brettcannon

Bug report

Bug description:

This is on VS Code insiders on Windows with a checkout in WSL.

➲ ./python -m test test_repl
Using random seed: 506736770
0:00:00 load avg: 0.01 Run 1 test sequentially in a single process
0:00:00 load avg: 0.01 [1/1] test_repl
test test_repl failed -- Traceback (most recent call last):
  File "/home/brett/Repositories/python/cpython/Lib/test/test_repl.py", line 339, in test_toplevel_contextvars_async
    self.assertIn(expected, output, expected)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'toplevel contextvar test: ok' not found in 'asyncio REPL 3.15.0a0 (heads/main-dirty:d7dbde89588, Aug  8 2025, 14:49:47) [Clang 14.0.6 ] on linux\nUse "await" directly instead of "asyncio.run()".\nType "help", "copyright", "credits" or "license" for more information.\nException in thread Interactive thread:\nexiting asyncio REPL...\nTraceback (most recent call last):\nTraceback (most recent call last):\n  File "/home/brett/Repositories/python/cpython/Lib/runpy.py", line 198, in _run_module_as_main\n    return _run_code(code, main_globals, None,\n                     "__main__", mod_spec)\n  File "/home/brett/Repositories/python/cpython/Lib/threading.py", line 1074, in _bootstrap_inner\n    self._context.run(self.run)\n    ~~~~~~~~~~~~~~~~~^^^^^^^^^^\n  File "/home/brett/Repositories/python/cpython/Lib/asyncio/__main__.py", line 105, in run\n    exec(startup_code, console.locals)\n    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/home/brett/.vscode-server-insiders/data/User/workspaceStorage/0abd4bd2132dfcbfde5adbe8d7792ee2/ms-python.python/pythonrc.py", line 5, in <module>\n    import readline\nModuleNotFoundError: No module named \'readline\'\n  File "/home/brett/Repositories/python/cpython/Lib/runpy.py", line 88, in _run_code\n    exec(code, run_globals)\n    ~~~~^^^^^^^^^^^^^^^^^^^\n  File "/home/brett/Repositories/python/cpython/Lib/asyncio/__main__.py", line 245, in <module>\n    sys.exit(return_code)\n    ~~~~~~~~^^^^^^^^^^^^^\nSystemExit: 0\n>>> >>> >>> ...   File "<stdin>", line 2\n    await set_var()\n    ^^^^^\nSyntaxError: invalid syntax\n>>> toplevel contextvar test: failed\n>>> \n' : toplevel contextvar test: ok

0:00:00 load avg: 0.17 [1/1/1] test_repl failed (1 failure)

== Tests result: FAILURE ==

1 test failed:
    test_repl

Total duration: 846 ms
Total tests: run=13 failures=1
Total test files: run=1/1 failed=1
Result: FAILURE

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Activity

  1. johnslavik commented on Oct 18, 2025

    @johnslavik
    Member

    I wrote that test -- will take a look at it.

  2. johnslavik commented on Oct 18, 2025

    @johnslavik
    Member

    Oh, it's in the traceback.

    AssertionError: 'toplevel contextvar test: ok' not found in s
    

    where s is:

    asyncio REPL 3.15.0a0 (heads/main-dirty:d7dbde89588, Aug  8 2025, 14:49:47) [Clang 14.0.6 ] on linux
    Use "await" directly instead of "asyncio.run()".
    Type "help", "copyright", "credits" or "license" for more information.
    Exception in thread Interactive thread:
    exiting asyncio REPL...
    Traceback (most recent call last):
    Traceback (most recent call last):
      File "/home/brett/Repositories/python/cpython/Lib/runpy.py", line 198, in _run_module_as_main
        return _run_code(code, main_globals, None,
                         "__main__", mod_spec)
      File "/home/brett/Repositories/python/cpython/Lib/threading.py", line 1074, in _bootstrap_inner
        self._context.run(self.run)
        ~~~~~~~~~~~~~~~~~^^^^^^^^^^
      File "/home/brett/Repositories/python/cpython/Lib/asyncio/__main__.py", line 105, in run
        exec(startup_code, console.locals)
        ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/brett/.vscode-server-insiders/data/User/workspaceStorage/0abd4bd2132dfcbfde5adbe8d7792ee2/ms-python.python/pythonrc.py", line 5, in <module>
        import readline
    ModuleNotFoundError: No module named 'readline'
      File "/home/brett/Repositories/python/cpython/Lib/runpy.py", line 88, in _run_code
        exec(code, run_globals)
        ~~~~^^^^^^^^^^^^^^^^^^^
      File "/home/brett/Repositories/python/cpython/Lib/asyncio/__main__.py", line 245, in <module>
        sys.exit(return_code)
        ~~~~~~~~^^^^^^^^^^^^^
    SystemExit: 0
    >>> >>> >>> ...   File "<stdin>", line 2
        await set_var()
        ^^^^^
    SyntaxError: invalid syntax
    >>> toplevel contextvar test: failed
    >>> 
    

    The asyncio REPL tries to import readline in a startup file and exits as part of #140287 that I've reported today independently, and then it spawns a regular REPL because the interpreter was run with the -i flag.

    Wow, what an interesting coincidence.

    The easiest workaround is to have readline available or remove it from your PYTHONSTARTUP.
    The fundamental question is why do we launch 2 REPLs in this test... (filed #140298 to fix)

  3. johnslavik commented on Oct 18, 2025

    @johnslavik
    Member

    @brettcannon This is just an instance of #140287. The asyncio REPL can work without readline, but you're trying to import readline in your startup file (/home/brett/.vscode-server-insiders/data/User/workspaceStorage/0abd4bd2132dfcbfde5adbe8d7792ee2/ms-python.python/pythonrc.py), it's unavailable, and the asyncio REPL doesn't handle PYTHONSTARTUP failures properly.

  4. johnslavik commented on Oct 18, 2025

    @johnslavik
    Member

    @ZeroIntensity (mentorship): Should we close this as duplicate or wait until the root issue is resolved and then close this afterwards?

  5. ZeroIntensity commented on Oct 18, 2025

    @ZeroIntensity
    Member

    This doesn't look like an exact copy of #140287, so let's keep this open for now.

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

    testsTests 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