@@ -31,14 +31,15 @@ with the fake file system functions and modules:
3131 The usage is explained in more detail in :ref: `auto_patch ` and
3232demonstrated in the files ``example.py `` and ``example_test.py ``.
3333
34- Patch using the PyTest plugin
34+ Patch using the pytest plugin
3535~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36- If you use `PyTest <https://doc.pytest.org >`__, you will be interested in
37- the PyTest plugin in ``pyfakefs ``.
36+ If you use `pytest <https://doc.pytest.org >`__, you will be interested in
37+ the pytest plugin in ``pyfakefs ``.
3838This automatically patches all file system functions and modules in a
3939similar manner as described above.
4040
41- The PyTest plugin provides the ``fs `` fixture for use in your test. For example:
41+ The pytest plugin provides the ``fs `` fixture for use in your test. For
42+ example:
4243
4344.. code :: python
4445
@@ -82,7 +83,8 @@ You can also initialize ``Patcher`` manually:
8283 Patch using fake_filesystem_unittest.patchfs decorator
8384~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8485This is basically a convenience wrapper for the previous method.
85- If you want to use the fake filesystem for a single function, you can write:
86+ If zou are not using ``pytest `` and want to use the fake filesystem for a
87+ single function, you can write:
8688
8789.. code :: python
8890
@@ -93,10 +95,25 @@ If you want to use the fake filesystem for a single function, you can write:
9395 # access the fake_filesystem object via fs
9496 fs.create_file(' /foo/bar' , contents = ' test' )
9597
96- Note the argument name ``fs ``, which is mandatory.
98+ Note the argument name ``fs ``, which is mandatory. As this is a keyword
99+ argument, it must go after all positional arguments, such as arguments from
100+ ``mock.patch ``, regardless of the decorator order:
97101
98- Don't confuse this with pytest tests, where ``fs `` is the fixture name (with
99- the same functionality). If you use pytest, you don't need this decorator.
102+ .. code :: python
103+
104+ @mock.patch (' foo.bar' )
105+ @patchfs
106+ def test_something (mocked_bar , fs ):
107+ ...
108+
109+ @patchfs
110+ @mock.patch (' foo.bar' )
111+ def test_something (mocked_bar , fs ):
112+ ...
113+
114+ Don't confuse this with ``pytest `` tests, where ``fs `` is the fixture name
115+ (with the same functionality). If you use ``pytest ``, you don't need this
116+ decorator.
100117
101118You can also use this to make a single unit test use the fake fs:
102119
@@ -136,7 +153,7 @@ the box.
136153In case of ``fake_filesystem_unittest.TestCase ``, these arguments can either
137154be set in the TestCase instance initialization, or passed to ``setUpPyfakefs() ``.
138155
139- .. note :: If you need these arguments in ``PyTest ``, you can pass them using
156+ .. note :: If you need these arguments in ``pytest ``, you can pass them using
140157 ``@pytest.mark.parametrize ``. Note that you have to also provide
141158 `all Patcher arguments <http://jmcgeheeiv.github.io/pyfakefs/master/modules.html#pyfakefs.fake_filesystem_unittest.Patcher >`__
142159 before the needed ones, as keyword arguments cannot be used, and you have to
@@ -149,7 +166,7 @@ be set in the TestCase instance initialization, or passed to ``setUpPyfakefs()``
149166 `pytest_fixture_test.py <https://github.com/jmcgeheeiv/pyfakefs/blob/master/pyfakefs/pytest_tests/pytest_fixture_test.py >`__
150167 with the example fixture in `conftest.py <https://github.com/jmcgeheeiv/pyfakefs/blob/master/pyfakefs/pytest_tests/conftest.py >`__.
151168 We advice to use this example fixture code as a template for your customized
152- pytest plugins.
169+ `` pytest `` plugins.
153170
154171modules_to_reload
155172~~~~~~~~~~~~~~~~~
@@ -348,7 +365,7 @@ Alternatively to the module names, the modules themselves may be used:
348365 patcher.fs.create_file(' foo' )
349366
350367 There is also the global variable ``Patcher.SKIPNAMES `` that can be extended
351- for that purpose, though this seldom shall be needed (except for own pytest
368+ for that purpose, though this seldom shall be needed (except for own `` pytest ``
352369plugins, as shown in the example mentioned above).
353370
354371allow_root_user
@@ -375,7 +392,7 @@ While ``pyfakefs`` can be used just with the standard Python file system
375392functions, there are few convenience methods in ``fake_filesystem `` that can
376393help you setting up your tests. The methods can be accessed via the
377394``fake_filesystem `` instance in your tests: ``Patcher.fs ``, the ``fs ``
378- fixture in PyTest , ``TestCase.fs `` for ``unittest ``, and the ``fs `` argument
395+ fixture in pytest , ``TestCase.fs `` for ``unittest ``, and the ``fs `` argument
379396for the ``patchfs `` decorator.
380397
381398File creation helpers
0 commit comments