Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bityob opened this issue Jul 12, 2023 · 5 comments
Closed

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

bityob opened this issue Jul 12, 2023 · 5 comments
Labels
OS-windows tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@bityob
Copy link
Contributor

bityob commented Jul 12, 2023

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

@bityob bityob added the type-bug An unexpected behavior, bug, or error label Jul 12, 2023
@eryksun
Copy link
Contributor

eryksun commented Jul 12, 2023

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.

@eryksun eryksun added tests Tests in the Lib/test dir OS-windows labels Jul 12, 2023
@Eclips4
Copy link
Member

Eclips4 commented Aug 15, 2023

Bisected to #105154
cc @vstinner

vstinner added a commit to vstinner/cpython that referenced this issue Aug 16, 2023
Use config.legacy_windows_stdio=1 to avoid _io._WindowsConsoleIO.
@vstinner
Copy link
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.

@vstinner
Copy link
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.

vstinner added a commit that referenced this issue Aug 16, 2023
Use config.legacy_windows_stdio=1 to avoid _io._WindowsConsoleIO.
@Eclips4 Eclips4 closed this as completed Aug 16, 2023
@vstinner
Copy link
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
Labels
OS-windows tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants