Skip to content

Test test_embed fails on Windows 11, Python 3.13.0a0 #106659

Description

@bityob

Bug report

The test test_embed fails on my Windows machine, using master branch (commit d0972c7).

python.bat -m test test_embed

Full output -

C:\Code\cpython>python.bat -m test test_embed
Running Debug|x64 interpreter...
0:00:00 Run tests sequentially
0:00:00 [1/1] test_embed
test test_embed failed -- Traceback (most recent call last):
  File "C:\Code\cpython\Lib\test\test_embed.py", line 259, in test_forced_io_encoding
    self.assertEqual(out.strip(), expected_output)
AssertionError: '--- [403 chars]din: utf-8:surrogateescape\nstdout: iso8859-1:[221 chars]lace' != '--- [403 chars]din: iso8859-1:surrogateescape\nstdout: iso885[229 chars]lace'
  --- Use defaults ---
  Expected encoding: default
  Expected errors: default
  stdin: utf-8:surrogateescape
  stdout: utf-8:surrogateescape
  stderr: utf-8:backslashreplace
  --- Set errors only ---
  Expected encoding: default
  Expected errors: ignore
  stdin: utf-8:ignore
  stdout: utf-8:ignore
  stderr: utf-8:backslashreplace
  --- Set encoding only ---
  Expected encoding: iso8859-1
  Expected errors: default
- stdin: utf-8:surrogateescape
?        ^^^ ^
+ stdin: iso8859-1:surrogateescape
?        ^^^^^^^ ^
  stdout: iso8859-1:surrogateescape
  stderr: iso8859-1:backslashreplace
  --- Set encoding and errors ---
  Expected encoding: iso8859-1
  Expected errors: replace
- stdin: utf-8:replace
+ stdin: iso8859-1:replace
  stdout: iso8859-1:replace
  stderr: iso8859-1:backslashreplace


test_embed failed (1 failure) in 30.7 sec

== Tests result: FAILURE ==

1 test failed:
    test_embed

Total duration: 30.7 sec
Tests result: FAILURE

Your environment

  • CPython versions tested on:
Running Debug|x64 interpreter...
Python 3.13.0a0
  • Commit: d0972c7
  • Operating system and architecture:
OS Name:                   Microsoft Windows 11 Pro
OS Version:                10.0.22621 N/A Build 22621

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Jul 12, 2023
  2. eryksun commented on Jul 12, 2023

    @eryksun
    Contributor

    The test doesn't override sys.stdin in the child process. Thus when it's run normally, stdin is a console file. By default, the raw type of a console file is io._WindowsConsoleIO, which always uses UTF-8. The test expects to be able to override this, but being able to do this will either require forcing stdin to be a pipe or nul or it will require defining the environment variable PYTHONLEGACYWINDOWSSTDIO. The latter forces the use of io.FileIO for console files, instead of io._WindowsConsoleIO.

  3. Eclips4 commented on Aug 15, 2023

    @Eclips4
    Member

    Bisected to #105154
    cc @vstinner

  4. added a commit that references this issue on Aug 16, 2023
  5. vstinner commented on Aug 16, 2023

    @vstinner
    Member

    Bisected to #105154 cc @vstinner

    Oh thanks for the bisect! I wrote PR #108010 to fix the regression. I'm able to reproduce the test failure on Windows when I run the test manually in a terminal.

  6. vstinner commented on Aug 16, 2023

    @vstinner
    Member

    The test expects to be able to override this, but being able to do this will either require forcing stdin to be a pipe or nul or it will require defining the environment variable PYTHONLEGACYWINDOWSSTDIO.

    The removed Py_SetStandardStreamEncoding() function did set Py_LegacyWindowsStdioFlag:

            /* Overriding the stream encoding implies legacy streams */
            Py_LegacyWindowsStdioFlag = 1;

    I missed that in my change. My PR fix it.

  7. added a commit that references this issue on Aug 16, 2023
  8. vstinner commented on Aug 16, 2023

    @vstinner
    Member

    It should now be fixed. Thanks for your bug report! Thanks @Eclips4 for your review on my PR.

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

    OS-windowstestsTests 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