Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/9910.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix default encoding warning (``EncodingWarning``) in ``cacheprovider``
8 changes: 4 additions & 4 deletions src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get(self, key: str, default):
"""
path = self._getvaluepath(key)
try:
with path.open("r") as f:
with path.open("r", encoding="UTF-8") as f:
return json.load(f)
except (ValueError, OSError):
return default
Expand All @@ -184,9 +184,9 @@ def set(self, key: str, value: object) -> None:
return
if not cache_dir_exists_already:
self._ensure_supporting_files()
data = json.dumps(value, indent=2)
data = json.dumps(value, ensure_ascii=False, indent=2)
try:
f = path.open("w")
f = path.open("w", encoding="UTF-8")
except OSError:
self.warn("cache could not write path {path}", path=path, _ispytest=True)
else:
Expand All @@ -196,7 +196,7 @@ def set(self, key: str, value: object) -> None:
def _ensure_supporting_files(self) -> None:
"""Create supporting files in the cache dir that are not really part of the cache."""
readme_path = self._cachedir / "README.md"
readme_path.write_text(README_CONTENT)
readme_path.write_text(README_CONTENT, encoding="UTF-8")

gitignore_path = self._cachedir.joinpath(".gitignore")
msg = "# Created by pytest automatically.\n*\n"
Expand Down