Skip to content

fix(tests): fix Windows test failures with click 8.2 encoding#2

Open
bobo-xxx wants to merge 1 commit into
mainfrom
clawoss/fix-windows-encoding
Open

fix(tests): fix Windows test failures with click 8.2 encoding#2
bobo-xxx wants to merge 1 commit into
mainfrom
clawoss/fix-windows-encoding

Conversation

@bobo-xxx
Copy link
Copy Markdown
Owner

Fixes Windows test failures related to click 8.2 encoding issues.

Problem

Windows uses CP1252 encoding by default, which cannot handle Unicode characters output by click.echo(). This causes test failures on Windows when using click 8.2+ with error messages like:

UnicodeEncodeError: 'charmap' codec can't encode character '\u2023' in position X: character maps to <undefined>

Solution

Set PYTHONIOENCODING=utf-8 environment variable to ensure proper Unicode handling:

  1. tests/conftest.py: Added fix_windows_encoding fixture that sets PYTHONIOENCODING=utf-8 at module level for Windows platform during test collection
  2. tox.ini: Added setenv = PYTHONIOENCODING=utf-8 for all test environments

Changes

  • Added fix_windows_encoding autouse session fixture in tests/conftest.py
  • Added PYTHONIOENCODING=utf-8 via setenv in tox.ini testenv configuration

Fixes encoding issues that cause UnicodeEncodeError on Windows when tests output Unicode characters through click.echo().

Set PYTHONIOENCODING=utf-8 environment variable for Windows platform
to ensure proper Unicode handling when tests output Unicode characters
through click.echo().

Fixes encoding issues that cause UnicodeEncodeError on Windows when
tests output Unicode characters.
Copilot AI review requested due to automatic review settings April 18, 2026 08:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts the test environment to avoid Windows CP1252 stdout/stderr encoding errors triggered by Unicode output in Click 8.2+.

Changes:

  • Set PYTHONIOENCODING=utf-8 in tox.ini for test environments.
  • Added a Windows-only autouse session fixture in tests/conftest.py intended to force UTF-8 I/O behavior during tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tox.ini Forces UTF-8 I/O encoding for tox-driven test runs to prevent Windows Unicode encoding failures.
tests/conftest.py Adds a session autouse fixture attempting to mitigate Windows encoding issues during pytest execution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/conftest.py
Comment on lines +20 to +23
if sys.platform == "win32":
os.environ["PYTHONIOENCODING"] = "utf-8"


Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting PYTHONIOENCODING inside a pytest fixture won’t reconfigure the already-created sys.stdout/sys.stderr for the current Python process (Python only uses PYTHONIOENCODING at interpreter startup). This means the fixture is unlikely to prevent the UnicodeEncodeError coming from click.echo() writing to stdout on Windows when running python -m pytest. Consider either (a) relying solely on tox/CI to set PYTHONIOENCODING before Python starts and remove this fixture, or (b) in this fixture, reconfigure sys.stdout/sys.stderr to UTF-8 (and optionally only set the env var via setdefault for subprocesses).

Suggested change
if sys.platform == "win32":
os.environ["PYTHONIOENCODING"] = "utf-8"
if sys.platform != "win32":
return
os.environ.setdefault("PYTHONIOENCODING", "utf-8")
for stream in (sys.stdout, sys.stderr):
if stream is not None and hasattr(stream, "reconfigure"):
stream.reconfigure(encoding="utf-8")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants