Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import pytest
from utils import (
POSTGRES_HOST,
Expand All @@ -13,6 +14,13 @@
import pgcli.pgexecute


# Fix for Windows encoding issues with click 8.2+
@pytest.fixture(autouse=True, scope="session")
def fix_windows_encoding():
if sys.platform == "win32":
os.environ["PYTHONIOENCODING"] = "utf-8"


Comment on lines +20 to +23
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.
@pytest.fixture(scope="function")
def connection():
create_db("_test_db")
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ envlist = py
[testenv]
skip_install = true
deps = uv
setenv = PYTHONIOENCODING=utf-8
commands = uv pip install -e .[dev]
coverage run -m pytest -v tests
coverage report -m
Expand Down