Skip to content

Commit

Permalink
Encoding for subprocess.run
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Jun 20, 2023
1 parent a704605 commit 7e51076
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import contextlib
import gc
import importlib
import locale
import os
import platform
import re
Expand Down Expand Up @@ -129,6 +130,7 @@ def get_open_files(self) -> List[Tuple[str, str]]:
stderr=subprocess.DEVNULL,
check=True,
text=True,
encoding=locale.getpreferredencoding(False),
).stdout

def isopen(line: str) -> bool:
Expand Down
6 changes: 6 additions & 0 deletions testing/test_parseopt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import locale
import os
import shlex
import subprocess
Expand Down Expand Up @@ -289,13 +290,18 @@ def test_multiple_metavar_help(self, parser: parseopt.Parser) -> None:


def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
try:
encoding = locale.getencoding() # New in Python 3.11, ignores utf-8 mode
except AttributeError:
encoding = locale.getpreferredencoding(False)
try:
bash_version = subprocess.run(
["bash", "--version"],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
check=True,
text=True,
encoding=encoding,
).stdout
except (OSError, subprocess.CalledProcessError):
pytest.skip("bash is not available")
Expand Down

0 comments on commit 7e51076

Please sign in to comment.