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

Function test_delattr

testing/test_monkeypatch.py:117–135  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

115
116
117def test_delattr() -> None:
118 class A:
119 x = 1
120
121 monkeypatch = MonkeyPatch()
122 monkeypatch.delattr(A, "x")
123 assert not hasattr(A, "x")
124 monkeypatch.undo()
125 assert A.x == 1
126
127 monkeypatch = MonkeyPatch()
128 monkeypatch.delattr(A, "x")
129 with pytest.raises(AttributeError):
130 monkeypatch.delattr(A, "y")
131 monkeypatch.delattr(A, "y", raising=False)
132 monkeypatch.setattr(A, "x", 5, raising=False)
133 assert A.x == 5
134 monkeypatch.undo()
135 assert A.x == 1
136
137
138def test_setitem() -> None:

Callers

nothing calls this directly

Calls 4

delattrMethod · 0.95
undoMethod · 0.95
setattrMethod · 0.95
MonkeyPatchClass · 0.90

Tested by

no test coverage detected