Skip to content

Commit 7e51076

Browse files
committed
Encoding for subprocess.run
1 parent a704605 commit 7e51076

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/_pytest/pytester.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import contextlib
77
import gc
88
import importlib
9+
import locale
910
import os
1011
import platform
1112
import re
@@ -129,6 +130,7 @@ def get_open_files(self) -> List[Tuple[str, str]]:
129130
stderr=subprocess.DEVNULL,
130131
check=True,
131132
text=True,
133+
encoding=locale.getpreferredencoding(False),
132134
).stdout
133135

134136
def isopen(line: str) -> bool:

testing/test_parseopt.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import locale
23
import os
34
import shlex
45
import subprocess
@@ -289,13 +290,18 @@ def test_multiple_metavar_help(self, parser: parseopt.Parser) -> None:
289290

290291

291292
def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
293+
try:
294+
encoding = locale.getencoding() # New in Python 3.11, ignores utf-8 mode
295+
except AttributeError:
296+
encoding = locale.getpreferredencoding(False)
292297
try:
293298
bash_version = subprocess.run(
294299
["bash", "--version"],
295300
stdout=subprocess.PIPE,
296301
stderr=subprocess.DEVNULL,
297302
check=True,
298303
text=True,
304+
encoding=encoding,
299305
).stdout
300306
except (OSError, subprocess.CalledProcessError):
301307
pytest.skip("bash is not available")

0 commit comments

Comments
 (0)