Skip to content
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

Fix UnicodeEncodeError when running unit tests in Windows #16497

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/internals/contributing/writing-code/unit-tests.txt
Expand Up @@ -433,6 +433,26 @@ Run the ``locale`` command to confirm the change. Optionally, add those export
commands to your shell's startup file (e.g. ``~/.bashrc`` for Bash) to avoid
having to retype them.

You can resolve this for Windows by passing ``encoding`` when opening the PO_FILE:

.. code-block:: python
:caption: ``tests/i18n/test_percents.py``

with open(self.PO_FILE) as fp:

to:

.. code-block:: python
:caption: ``tests/i18n/test_percents.py``

with open(self.PO_FILE, encoding="utf-8") as fp:

Then run again an individual test method like this (e.g. test_adds_python_format_to_all_percent_signs):

.. console::

$ ./runtests.py i18n.test_percents.ExtractingStringsWithPercentSigns.test_adds_python_format_to_all_percent_signs

Tests that only fail in combination
-----------------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/i18n/test_percents.py
Expand Up @@ -40,7 +40,7 @@ class ExtractingStringsWithPercentSigns(POFileAssertionMixin, FrenchTestCase):

def setUp(self):
super().setUp()
with open(self.PO_FILE) as fp:
with open(self.PO_FILE, encoding="utf-8") as fp:
self.po_contents = fp.read()

def test_trans_tag_with_percent_symbol_at_the_end(self):
Expand Down