Skip to content

Commit 3cdd0a5

Browse files
Force UTF-8 in CLI subprocess tests for Windows
The info command prints unicode box-drawing characters, which crash the child process with a UnicodeEncodeError when stdout is a pipe on platforms defaulting to a non-UTF-8 codec (e.g. Windows). Set PYTHONIOENCODING=utf-8 in the subprocess environment.
1 parent b60e819 commit 3cdd0a5

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

python/tests/test_cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,15 @@ class TestStdinSubprocess:
776776
"""
777777

778778
def run_cli(self, args, input_bytes):
779+
# Force UTF-8 stdout in the child so that commands printing unicode (e.g.
780+
# the box-drawing characters from "info") don't fail when stdout is a
781+
# pipe on platforms that default to a non-UTF-8 codec (e.g. Windows).
782+
env = {**os.environ, "PYTHONIOENCODING": "utf-8"}
779783
return subprocess.run(
780784
[sys.executable, "-m", "tskit", *args],
781785
input=input_bytes,
782786
capture_output=True,
787+
env=env,
783788
)
784789

785790
@pytest.mark.parametrize("subcommand", [["info"], ["vcf", "-0"], ["nodes"]])

0 commit comments

Comments
 (0)