Skip to content

Commit 4b7148f

Browse files
authored
cacheprovider: set: use json.dumps + write (#6206)
2 parents c49c61f + 786d839 commit 4b7148f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

changelog/6206.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cacheprovider: improved robustness and performance with ``cache.set``.

src/_pytest/cacheprovider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,14 @@ def set(self, key, value):
125125
return
126126
if not cache_dir_exists_already:
127127
self._ensure_supporting_files()
128+
data = json.dumps(value, indent=2, sort_keys=True)
128129
try:
129130
f = path.open("w")
130131
except (IOError, OSError):
131132
self.warn("cache could not write path {path}", path=path)
132133
else:
133134
with f:
134-
json.dump(value, f, indent=2, sort_keys=True)
135+
f.write(data)
135136

136137
def _ensure_supporting_files(self):
137138
"""Create supporting files in the cache dir that are not really part of the cache."""

0 commit comments

Comments
 (0)