Skip to content

Commit 0eceb49

Browse files
committed
Add encoding to subprocess.run inside setuptools/tests
1 parent 3115855 commit 0eceb49

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

setuptools/tests/integration/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def run(cmd, env=None):
1717
cmd,
1818
capture_output=True,
1919
text=True,
20+
encoding="utf-8",
2021
env={**os.environ, **(env or {})},
2122
# ^-- allow overwriting instead of discarding the current env
2223
)

setuptools/tests/test_dist_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ def run_command_inner(*cmd, **kwargs):
198198
"stderr": subprocess.STDOUT,
199199
"stdout": subprocess.PIPE,
200200
"text": True,
201-
'check': True,
201+
"encoding": "utf-8",
202+
"check": True,
202203
**kwargs,
203204
}
204205
cmd = [sys.executable, "-c", "__import__('setuptools').setup()", *map(str, cmd)]

setuptools/tests/test_distutils_adoption.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
IS_PYPY = '__pypy__' in sys.builtin_module_names
1010

11+
_TEXT_KWARGS = {"text": True, "encoding": "utf-8"} # For subprocess.run
12+
1113

1214
def win_sr(env):
1315
"""
@@ -24,7 +26,7 @@ def win_sr(env):
2426
def find_distutils(venv, imports='distutils', env=None, **kwargs):
2527
py_cmd = 'import {imports}; print(distutils.__file__)'.format(**locals())
2628
cmd = ['python', '-c', py_cmd]
27-
return venv.run(cmd, env=win_sr(env), text=True, **kwargs)
29+
return venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS, **kwargs)
2830

2931

3032
def count_meta_path(venv, env=None):
@@ -36,7 +38,7 @@ def count_meta_path(venv, env=None):
3638
"""
3739
)
3840
cmd = ['python', '-c', py_cmd]
39-
return int(venv.run(cmd, env=win_sr(env), text=True))
41+
return int(venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS))
4042

4143

4244
skip_without_stdlib_distutils = pytest.mark.skipif(
@@ -82,7 +84,7 @@ def test_pip_import(venv):
8284
Regression test for #3002.
8385
"""
8486
cmd = ['python', '-c', 'import pip']
85-
venv.run(cmd, text=True)
87+
venv.run(cmd, **_TEXT_KWARGS)
8688

8789

8890
def test_distutils_has_origin():
@@ -130,7 +132,7 @@ def test_modules_are_not_duplicated_on_import(
130132
env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
131133
script = ENSURE_IMPORTS_ARE_NOT_DUPLICATED.format(imported_module=imported_module)
132134
cmd = ['python', '-c', script]
133-
output = venv.run(cmd, env=win_sr(env), text=True).strip()
135+
output = venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS).strip()
134136
assert output == "success"
135137

136138

@@ -154,5 +156,5 @@ def test_modules_are_not_duplicated_on_import(
154156
def test_log_module_is_not_duplicated_on_import(distutils_version, tmpdir_cwd, venv):
155157
env = dict(SETUPTOOLS_USE_DISTUTILS=distutils_version)
156158
cmd = ['python', '-c', ENSURE_LOG_IMPORT_IS_NOT_DUPLICATED]
157-
output = venv.run(cmd, env=win_sr(env), text=True).strip()
159+
output = venv.run(cmd, env=win_sr(env), **_TEXT_KWARGS).strip()
158160
assert output == "success"

setuptools/tests/test_easy_install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ def test_setup_install_includes_dependencies(self, tmp_path, mock_index):
530530
stdout=subprocess.PIPE,
531531
stderr=subprocess.STDOUT,
532532
text=True,
533+
encoding="utf-8",
533534
)
534535
assert cp.returncode != 0
535536
try:

0 commit comments

Comments
 (0)