From f1f539a7f63336830003cac671d165423f4db73c Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Mon, 30 Sep 2019 17:57:40 -0700 Subject: [PATCH] Fix encoding issues in pytest stdio logs. --- tests/pytest_fixtures.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/pytest_fixtures.py b/tests/pytest_fixtures.py index 0c15b86f..17c8495a 100644 --- a/tests/pytest_fixtures.py +++ b/tests/pytest_fixtures.py @@ -5,7 +5,6 @@ from __future__ import absolute_import, print_function, unicode_literals import inspect -import io import os import platform import py.path @@ -68,7 +67,9 @@ def test_wrapper(request, long_tmpdir): def write_log(filename, data): filename = os.path.join(options.log_dir, filename) - with io.open(filename, "w", encoding="utf-8") as f: + if not isinstance(data, bytes): + data = data.encode("utf-8") + with open(filename, "wb") as f: f.write(data) print("\n") # make sure on-screen logs start on a new line