Skip to content

Commit 762bb61

Browse files
authored
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.
1 parent 725de3a commit 762bb61

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/_pytest/_py/path.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ def ensure(self, *args, **kwargs):
953953
else:
954954
p.dirpath()._ensuredirs()
955955
if not p.check(file=1):
956-
p.open("w").close()
956+
p.open("wb").close()
957957
return p
958958

959959
@overload

src/_pytest/faulthandler.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def pytest_configure(config: Config) -> None:
2727
import faulthandler
2828

2929
stderr_fd_copy = os.dup(get_stderr_fileno())
30-
config.stash[fault_handler_stderr_key] = open(stderr_fd_copy, "w")
30+
config.stash[fault_handler_stderr_key] = open(
31+
stderr_fd_copy, "w", encoding=sys.stderr.encoding
32+
)
3133
config.stash[fault_handler_originally_enabled_key] = faulthandler.is_enabled()
3234
faulthandler.enable(file=config.stash[fault_handler_stderr_key])
3335

0 commit comments

Comments
 (0)