Open
Description
running pytest --doctest-plus-generate-diff=overwrite
on a windows machine raise an an fatal error and
source files will be empty afterwards.
test
content of a utf-8 encoded file
def test_win_fail():
"""
fatal failure on windows when file contains utf-8 charaters, due default encoding is "cp1252" and not "utf-8".
reason: `open() is used without possibility to specify encoding`
`pytest --doctest-plus-generate-diff=overwrite`
>>> print("✅")
💥
"""
assert True
Exception
File "D:\doctestplus\.venv\src\pytest-doctestplus\pytest_doctestplus\plugin.py", line 950, in write_modified_file
f.write("".join(text))
~~~~~~~^^^^^^^^^^^^^^^
File "C:\Python313\Lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u2705' in position 357: character maps to <undefined>
solution
introduce new cli or ini option to specify file encoding
workaround
none