From 8288b52090c326f0e64f91f93ceb7d77c84b103a Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 28 Apr 2023 23:02:04 +0300 Subject: [PATCH 1/3] faulthandler: fix an EncodingWarning --- src/_pytest/faulthandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/faulthandler.py b/src/_pytest/faulthandler.py index b9c925582ca..f54e2024a48 100644 --- a/src/_pytest/faulthandler.py +++ b/src/_pytest/faulthandler.py @@ -27,7 +27,7 @@ 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]) From 43f610abf429ac482c01dc85b955f34f3507eab6 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 28 Apr 2023 23:04:22 +0300 Subject: [PATCH 2/3] _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 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/_py/path.py b/src/_pytest/_py/path.py index fb64830f814..73a070d19a8 100644 --- a/src/_pytest/_py/path.py +++ b/src/_pytest/_py/path.py @@ -953,7 +953,7 @@ def ensure(self, *args, **kwargs): else: p.dirpath()._ensuredirs() if not p.check(file=1): - p.open("w").close() + p.open("wb").close() return p @overload From 05d2f7e9d2783bb4b44b49d574012b9b505da052 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 20:19:56 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/faulthandler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/_pytest/faulthandler.py b/src/_pytest/faulthandler.py index f54e2024a48..ed29346babd 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", encoding=sys.stderr.encoding) + 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])