1
+ ===========
1
2
pytest-mock
2
3
===========
3
4
4
- This plugin installs a fixture ``mock `` which is a thin-wrapper around the patching API
5
+ This plugin installs a ``mock `` fixture which is a thin-wrapper around the patching API
5
6
provided by the excellent `mock <http://pypi.python.org/pypi/mock >`_ package,
6
7
but with the benefit of not having to worry about undoing patches at the end
7
8
of a test:
@@ -16,28 +17,29 @@ of a test:
16
17
17
18
18
19
Usage
19
- -----
20
+ =====
20
21
21
22
The ``mock `` fixture has the same API as
22
23
`mock.patch <http://www.voidspace.org.uk/python/mock/patch.html#patch-decorators >`_,
23
24
supporting the same arguments:
24
25
25
26
.. code-block :: python
26
27
27
- # all valid calls
28
- mock.patch(' os.remove' )
29
- mock.patch.object(os, ' listdir' , autospec = True )
30
- mocked = mock.patch(' os.remove' )
28
+ def test_foo (mock ):
29
+ # all valid calls
30
+ mock.patch(' os.remove' )
31
+ mock.patch.object(os, ' listdir' , autospec = True )
32
+ mocked = mock.patch(' os.path.isfile' )
31
33
32
34
The supported methods are:
33
35
34
36
* ``mock.patch ``: see http://www.voidspace.org.uk/python/mock/patch.html#patch.
35
- * ``mock.patch.object ``: see ` http://www.voidspace.org.uk/python/mock/patch.html#patch-object.
36
- * ``mock.patch.multiple``: see ` http://www.voidspace.org.uk/python/mock/patch.html#patch-multiple.
37
+ * ``mock.patch.object ``: see http://www.voidspace.org.uk/python/mock/patch.html#patch-object.
38
+ * ``mock.patch.multiple ``: see http://www.voidspace.org.uk/python/mock/patch.html#patch-multiple.
37
39
* ``mock.stopall() ``: stops all active patches at this point.
38
40
39
41
Why bother with a plugin?
40
- -------------------------
42
+ =========================
41
43
42
44
There are a number of different ``patch `` usages in the standard ``mock `` API,
43
45
but IMHO they don't scale very well when you have a more than one or two
0 commit comments