@@ -14,18 +14,16 @@ environment variable, or to modify ``sys.path`` for importing.
14
14
The ``monkeypatch `` fixture provides these helper methods for safely patching and mocking
15
15
functionality in tests:
16
16
17
- .. code-block :: python
17
+ * :meth: `monkeypatch.setattr(obj, name, value, raising=True) <pytest.MonkeyPatch.setattr> `
18
+ * :meth: `monkeypatch.delattr(obj, name, raising=True) <pytest.MonkeyPatch.delattr> `
19
+ * :meth: `monkeypatch.setitem(mapping, name, value) <pytest.MonkeyPatch.setitem> `
20
+ * :meth: `monkeypatch.delitem(obj, name, raising=True) <pytest.MonkeyPatch.delitem> `
21
+ * :meth: `monkeypatch.setenv(name, value, prepend=None) <pytest.MonkeyPatch.setenv> `
22
+ * :meth: `monkeypatch.delenv(name, raising=True) <pytest.MonkeyPatch.delenv> `
23
+ * :meth: `monkeypatch.syspath_prepend(path) <pytest.MonkeyPatch.syspath_prepend> `
24
+ * :meth: `monkeypatch.chdir(path) <pytest.MonkeyPatch.chdir> `
25
+ * :meth: `monkeypatch.context() <pytest.MonkeyPatch.context> `
18
26
19
- monkeypatch.setattr(obj, name, value, raising = True )
20
- monkeypatch.setattr(" somemodule.obj.name" , value, raising = True )
21
- monkeypatch.delattr(obj, name, raising = True )
22
- monkeypatch.setitem(mapping, name, value)
23
- monkeypatch.delitem(obj, name, raising = True )
24
- monkeypatch.setenv(name, value, prepend = None )
25
- monkeypatch.delenv(name, raising = True )
26
- monkeypatch.syspath_prepend(path)
27
- monkeypatch.chdir(path)
28
- monkeypatch.context()
29
27
30
28
All modifications will be undone after the requesting
31
29
test function or fixture has finished. The ``raising ``
@@ -64,8 +62,8 @@ and a discussion of its motivation.
64
62
65
63
.. _`monkeypatch blog post` : https://tetamap.wordpress.com//2009/03/03/monkeypatching-in-unit-tests-done-right/
66
64
67
- Simple example: monkeypatching functions
68
- ----------------------------------------
65
+ Monkeypatching functions
66
+ ------------------------
69
67
70
68
Consider a scenario where you are working with user directories. In the context of
71
69
testing, you do not want your test to depend on the running user. ``monkeypatch ``
0 commit comments