From 0a5adc87e4211420be7b669d79c95d17a5bbc5d5 Mon Sep 17 00:00:00 2001 From: BillionClaw Date: Mon, 16 Mar 2026 18:35:25 +0800 Subject: [PATCH] fix(tests): Fix Windows test failures related to click 8.2 encoding issues 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+. This fix sets PYTHONIOENCODING=utf-8 in: - tests/conftest.py: Set at module level for Windows platform - tox.ini: Set via setenv for all test environments Fixes encoding issues that cause UnicodeEncodeError on Windows when tests output Unicode characters through click.echo(). --- tests/conftest.py | 8 ++++++++ tox.ini | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index e50f1fe07..3a989f8b3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import os +import platform import pytest from utils import ( POSTGRES_HOST, @@ -13,6 +14,13 @@ import pgcli.pgexecute +# Fix Windows test failures related to click 8.2 encoding issues +# Windows uses CP1252 encoding by default, which can't handle Unicode characters +# Set PYTHONIOENCODING=utf-8 to ensure proper Unicode handling +if platform.system() == "Windows": + os.environ.setdefault("PYTHONIOENCODING", "utf-8") + + @pytest.fixture(scope="function") def connection(): create_db("_test_db") diff --git a/tox.ini b/tox.ini index 1b8ea025a..5ef2db01c 100644 --- a/tox.ini +++ b/tox.ini @@ -11,6 +11,9 @@ passenv = PGHOST PGPORT PGUSER PGPASSWORD + PYTHONIOENCODING +setenv = + PYTHONIOENCODING = utf-8 [testenv:style] skip_install = true @@ -23,6 +26,10 @@ skip_install = true deps = uv commands = uv pip install -e .[dev] behave tests/features --no-capture +passenv = + PYTHONIOENCODING +setenv = + PYTHONIOENCODING = utf-8 [testenv:rest] skip_install = true