aboutsummaryrefslogtreecommitdiffstats
path: root/library/python
diff options
context:
space:
mode:
authorzhukoff-pavel <zhukoff-pavel@yandex-team.com>2023-10-10 12:44:43 +0300
committerzhukoff-pavel <zhukoff-pavel@yandex-team.com>2023-10-10 13:22:19 +0300
commit86134366e9a506ecec1deb949f6f6669b2ae8ebd (patch)
tree00859c10fc5168c433b0742b31dbb49004d2a3da /library/python
parenta14f08a2b5d35a767003c3c71e4d6c33cff9647b (diff)
downloadydb-86134366e9a506ecec1deb949f6f6669b2ae8ebd.tar.gz
port all tests to py3
Diffstat (limited to 'library/python')
-rw-r--r--library/python/testing/yatest_common/yatest/common/process.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/library/python/testing/yatest_common/yatest/common/process.py b/library/python/testing/yatest_common/yatest/common/process.py
index 29ee702f65..e84f2abc08 100644
--- a/library/python/testing/yatest_common/yatest/common/process.py
+++ b/library/python/testing/yatest_common/yatest/common/process.py
@@ -1,5 +1,6 @@
# coding: utf-8
+import io
import os
import re
import time
@@ -547,13 +548,14 @@ def execute(
def get_out_stream(stream, default_name):
mode = 'w+t' if text else 'w+b'
+ open_kwargs = {'errors': 'ignore', 'encoding': 'utf-8'} if text else {}
if stream is None:
# No stream is supplied: open new temp file
- return _get_command_output_file(command, default_name, mode), False
+ return _get_command_output_file(command, default_name, mode, open_kwargs), False
if isinstance(stream, six.string_types):
# User filename is supplied: open file for writing
- return open(stream, mode), stream.startswith('/dev/')
+ return io.open(stream, mode, **open_kwargs), stream.startswith('/dev/')
# Open file or PIPE sentinel is supplied
is_pipe = stream == subprocess.PIPE
@@ -650,7 +652,9 @@ def execute(
return res
-def _get_command_output_file(cmd, ext, mode):
+def _get_command_output_file(cmd, ext, mode, open_kwargs=None):
+ if open_kwargs is None:
+ open_kwargs = {}
parts = [get_command_name(cmd)]
if 'YA_RETRY_INDEX' in os.environ:
parts.append('retry{}'.format(os.environ.get('YA_RETRY_INDEX')))
@@ -667,9 +671,9 @@ def _get_command_output_file(cmd, ext, mode):
raise ImportError("not in test")
filename = path.get_unique_file_path(yatest.common.output_path(), filename)
yatest_logger.debug("Command %s will be placed to %s", ext, os.path.basename(filename))
- return open(filename, mode)
+ return io.open(filename, mode, **open_kwargs)
except ImportError:
- return tempfile.NamedTemporaryFile(mode=mode, delete=False, suffix=filename)
+ return tempfile.NamedTemporaryFile(mode=mode, delete=False, suffix=filename, **(open_kwargs if six.PY3 else {}))
def _get_proc_tree_info(pids):