From 762bb61562d1300eedeb80be2ec2fb8150b3cc3f Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 29 Apr 2023 11:37:22 +0300 Subject: [PATCH] Fix couple of EncodingWarnings (#10954) * faulthandler: fix an EncodingWarning * _py/path: tiny change to `ensure` to silence EncodingWarning We're not supposed to diverge here, but make this change to fix an unavoidable EncodingWarning that is otherwise raised in pytest's test suite. The behavior should be exactly the same besides the warning, hopefully that won't cause confusion. --- src/_pytest/_py/path.py | 2 +- src/_pytest/faulthandler.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/_pytest/_py/path.py b/src/_pytest/_py/path.py index fb64830f8..73a070d19 100644 --- a/src/_pytest/_py/path.py +++ b/src/_pytest/_py/path.py @@ -953,7 +953,7 @@ class LocalPath: else: p.dirpath()._ensuredirs() if not p.check(file=1): - p.open("w").close() + p.open("wb").close() return p @overload diff --git a/src/_pytest/faulthandler.py b/src/_pytest/faulthandler.py index b9c925582..ed29346ba 100644 --- a/src/_pytest/faulthandler.py +++ b/src/_pytest/faulthandler.py @@ -27,7 +27,9 @@ def pytest_configure(config: Config) -> None: import faulthandler stderr_fd_copy = os.dup(get_stderr_fileno()) - config.stash[fault_handler_stderr_key] = open(stderr_fd_copy, "w") + config.stash[fault_handler_stderr_key] = open( + stderr_fd_copy, "w", encoding=sys.stderr.encoding + ) config.stash[fault_handler_originally_enabled_key] = faulthandler.is_enabled() faulthandler.enable(file=config.stash[fault_handler_stderr_key])