-
-
Notifications
You must be signed in to change notification settings - Fork 426
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
On Windows, test_wrong_alias_doesnt_work
fails if the error message contains bytes that UTF-8 cannot decode
#1777
Comments
I'm curious what non-ASCII characters are in the subprocess output? |
The error message received is:
Which decodes to:
Hm, there's a problem with my previous analysis: even though cp1252 is able to decode the output string, it's the wrong encoding. Running chcp shows that Windows Terminal is using cp850 instead. So I'm not sure using |
Sounds like |
I believe so, after looking for many alternatives. I've submitted #1780 so you can check a proposed way of doing it. |
…run_command() (Fix #1777) (#1780) * Use os.device_encoding(0) to figure out stdin encoding in run_command(). * Use the encoding of stdout (fd 1) to decode the output of subprocess.Popen. Co-authored-by: Ned Batchelder <[email protected]> * refactor to remove a helper used in only one place --------- Co-authored-by: Ned Batchelder <[email protected]>
Describe the bug
Running the tests on Windows,
tests/test_process.py::AliasedCommandTest::test_wrong_alias_doesnt_work
fails if the error message for the wrong alias contains bytes that UTF-8 cannot decode.To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:
The issue happens on this line:
coveragepy/tests/helpers.py
Line 65 in 695b8bc
From this code:
The issue is that on Windows
output
can have cp1252 as encoding andoutput_encoding()
will return UTF-8, leading to e.g.It can be reproduced by running the following code in Windows Terminal on Windows 11:
Expected behavior
run_command
should be able to handle output fromsubprocess.Popen
correctly.Additional context
I see some ways to fix this, not sure what is best. I'd prefer calling
locale.getpreferredencoding()
inrun_commands
, as it's about the encoding used to generate the error message. Another way would be to change the order in whichoutput_encoding
tries to get the right encoding. And the way I like the least, try decoding as it's currently done and uselocale.getpreferredencoding()
if that fails.I'll send a PR once we decide what's the best solution.
The text was updated successfully, but these errors were encountered: