kvas-it / pytest-console-scripts

Pytest plugin for testing console scripts
MIT License
78 stars 14 forks source link

Decode error when using inprocess tests on windows 10 #84

Closed arcsector closed 7 months ago

arcsector commented 1 year ago

What's still unclear to me, is how to convert your library that is using entry_points={"console_scripts":[]} in setup.py from working with only subprocess to working with inprocess... For me, testing on Windows, I only get the following error during inprocess execution:

Traceback (most recent call last):
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pytest_console_scripts.py", line 195, in exec_script
compiled = compile(script.read(), str(script), 'exec', flags=0)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byte

Perhaps this is a Windows-specific issue with decoding stdout and stderr?

Originally posted by @arcsector in https://github.com/kvas-it/pytest-console-scripts/issues/57#issuecomment-1787715887

Any help on this would be appreciated, as I know that since subprocess takes care of this automagically in the backend, this makes sense that it's only an inprocess issue.

HexDecimal commented 1 year ago

Looking at this again I'd expect this kind of encoding error to happen in subprocess rather than inprocess. Taking a closer look at the traceback seems to reveal that this is might be talking about the encoding of the script file itself and not stdout/stderr.

You should try converting/saving your script as UTF-8 if you can.