MCPcopy
hub / github.com/pytest-dev/pytest / set

Method set

src/_pytest/cacheprovider.py:206–235  ·  src/_pytest/cacheprovider.py::Cache.set

Save value for the given key. :param key: Must be a ``/`` separated value. Usually the first name is the name of your plugin or your application. :param value: Must be of any combination of basic python types, including nested types li

(self, key: str, value: object)

Source from the content-addressed store, hash-verified

204 return default
205
206 def set(self, key: str, value: object) -> None:
207 class="st">"""Save value for the given key.
208
209 :param key:
210 Must be a ``/`` separated value. Usually the first
211 name is the name of your plugin or your application.
212 :param value:
213 Must be of any combination of basic python types,
214 including nested types like lists of dictionaries.
215 class="st">"""
216 path = self._getvaluepath(key)
217 try:
218 self._mkdir(path.parent)
219 except OSError as exc:
220 self.warn(
221 fclass="st">"could not create cache path {path}: {exc}",
222 _ispytest=True,
223 )
224 return
225 data = json.dumps(value, ensure_ascii=False, indent=2)
226 try:
227 f = path.open(class="st">"w", encoding=class="st">"UTF-8")
228 except OSError as exc:
229 self.warn(
230 fclass="st">"cache could not write path {path}: {exc}",
231 _ispytest=True,
232 )
233 else:
234 with f:
235 f.write(data)
236
237 def _ensure_cache_dir_and_supporting_files(self) -> None:
238 class="st">""class="st">"Create the cache dir and its supporting files."class="st">""

Calls 6

_getvaluepathMethod · 0.95
_mkdirMethod · 0.95
warnMethod · 0.95
dumpsMethod · 0.80
openMethod · 0.80
writeMethod · 0.45