Merge pull request #11648 from bluetech/fix-locale-encoding
pytester: avoid EncodingWarning from `locale.getpreferredencoding`
This commit is contained in:
commit
5782aab017
|
@ -121,13 +121,18 @@ def pytest_configure(config: Config) -> None:
|
||||||
|
|
||||||
class LsofFdLeakChecker:
|
class LsofFdLeakChecker:
|
||||||
def get_open_files(self) -> List[Tuple[str, str]]:
|
def get_open_files(self) -> List[Tuple[str, str]]:
|
||||||
|
if sys.version_info >= (3, 11):
|
||||||
|
# New in Python 3.11, ignores utf-8 mode
|
||||||
|
encoding = locale.getencoding()
|
||||||
|
else:
|
||||||
|
encoding = locale.getpreferredencoding(False)
|
||||||
out = subprocess.run(
|
out = subprocess.run(
|
||||||
("lsof", "-Ffn0", "-p", str(os.getpid())),
|
("lsof", "-Ffn0", "-p", str(os.getpid())),
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
check=True,
|
check=True,
|
||||||
text=True,
|
text=True,
|
||||||
encoding=locale.getpreferredencoding(False),
|
encoding=encoding,
|
||||||
).stdout
|
).stdout
|
||||||
|
|
||||||
def isopen(line: str) -> bool:
|
def isopen(line: str) -> bool:
|
||||||
|
|
|
@ -290,10 +290,10 @@ class TestParser:
|
||||||
|
|
||||||
|
|
||||||
def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
|
def test_argcomplete(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
|
||||||
try:
|
if sys.version_info >= (3, 11):
|
||||||
# New in Python 3.11, ignores utf-8 mode
|
# New in Python 3.11, ignores utf-8 mode
|
||||||
encoding = locale.getencoding() # type: ignore[attr-defined]
|
encoding = locale.getencoding()
|
||||||
except AttributeError:
|
else:
|
||||||
encoding = locale.getpreferredencoding(False)
|
encoding = locale.getpreferredencoding(False)
|
||||||
try:
|
try:
|
||||||
bash_version = subprocess.run(
|
bash_version = subprocess.run(
|
||||||
|
|
Loading…
Reference in New Issue