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

Method delitem

src/_pytest/monkeypatch.py:294–306  ·  view source on GitHub ↗

Delete ``name`` from dict. Raises ``KeyError`` if it doesn't exist, unless ``raising`` is set to False.

(self, dic: Mapping[K, V], name: K, raising: bool = True)

Source from the content-addressed store, hash-verified

292 dic[name] = value # type: ignore[index]
293
294 def delitem(self, dic: Mapping[K, V], name: K, raising: bool = True) -> None:
295 """Delete ``name`` from dict.
296
297 Raises ``KeyError`` if it doesn't exist, unless ``raising`` is set to
298 False.
299 """
300 if name not in dic:
301 if raising:
302 raise KeyError(name)
303 else:
304 self._setitem.append((dic, name, dic.get(name, NOTSET)))
305 # Not all Mapping types support indexing, but MutableMapping doesn't support TypedDict
306 del dic[name] # type: ignore[attr-defined]
307
308 def setenv(self, name: str, value: str, prepend: str | None = None) -> None:
309 """Set environment variable ``name`` to ``value``.

Callers 4

delenvMethod · 0.95
test_delitemFunction · 0.95
test_cwd_changedMethod · 0.80

Calls 2

appendMethod · 0.80
getMethod · 0.45

Tested by 2

test_delitemFunction · 0.76
test_cwd_changedMethod · 0.64