Bug 1724766: Resolve Python 2->3 issue with Windows and Mochitest r=ahal

Environment variables should use their local `str` type.
The existing code was ensuring env vars were `bytes`, which is only
correct with Python 2.

I could've opted to simplify this and ensure environment variables were
always `text`, but I'm not confident that this code doesn't ever run
with Python 2 just yet. It is the `BaseRunner` after all.

Differential Revision: https://phabricator.services.mozilla.com/D122303
This commit is contained in:
Mitchell Hentges 2021-08-11 14:12:05 +00:00
Родитель 4a288852e3
Коммит b81f3fa8fa
1 изменённых файлов: 5 добавлений и 9 удалений

Просмотреть файл

@ -14,7 +14,7 @@ from abc import ABCMeta, abstractproperty
from mozlog import get_default_logger
from mozprocess import ProcessHandler
from six import string_types, text_type
from six import ensure_str, string_types
try:
import mozcrash
@ -129,22 +129,18 @@ class BaseRunner(object):
if self.logger:
self.logger.info("Application command: %s" % " ".join(cmd))
encoded_env = {}
str_env = {}
for k in self.env:
v = self.env[k]
if isinstance(v, text_type):
v = v.encode("utf-8")
if isinstance(k, text_type):
k = k.encode("utf-8")
encoded_env[k] = v
str_env[ensure_str(k)] = ensure_str(v)
if interactive:
self.process_handler = subprocess.Popen(cmd, env=encoded_env)
self.process_handler = subprocess.Popen(cmd, env=str_env)
# TODO: other arguments
else:
# this run uses the managed processhandler
try:
process = self.process_class(cmd, env=encoded_env, **self.process_args)
process = self.process_class(cmd, env=str_env, **self.process_args)
process.run(self.timeout, self.output_timeout)
self.process_handler = process