Skip to content

Commit

Permalink
Merge pull request #9915 from peymanslh/fix-encoding-warning
Browse files Browse the repository at this point in the history
Fix default encoding in cacheprovider
  • Loading branch information
bluetech committed May 9, 2022
2 parents 5f9d68c + 2f62e6e commit 933156b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
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

0 comments on commit 933156b

Please sign in to comment.