@@ -50,7 +50,8 @@ The PyTest plugin provides the ``fs`` fixture for use in your test. For example:
5050 Patch using fake_filesystem_unittest.Patcher
5151~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5252If you are using other means of testing like `nose <http://nose2.readthedocs.io >`__, you can do the
53- patching using ``fake_filesystem_unittest.Patcher `` - the class doing the actual work
53+ patching using ``fake_filesystem_unittest.Patcher ``--the class doing the
54+ actual work
5455of replacing the filesystem modules with the fake modules in the first two approaches.
5556
5657The easiest way is to just use ``Patcher `` as a context manager:
@@ -363,18 +364,19 @@ Some libraries are known to require patching in order to work with pyfakefs.
363364If ``use_known_patches `` is set to ``True `` (the default), pyfakefs patches
364365these libraries so that they will work with the fake filesystem. Currently, this
365366includes patches for ``pandas `` read methods like ``read_csv `` and
366- ``read_excel ``--more may follow. Ordinarily, the default value of
367- ``use_known_patches `` should be used, but it is present to allow users to
368- disable this patching in case it causes any problems. It may be removed or
369- replaced by more fine-grained arguments in future releases.
367+ ``read_excel ``, and for `` Django `` file locks --more may follow. Ordinarily,
368+ the default value of ``use_known_patches `` should be used, but it is present
369+ to allow users to disable this patching in case it causes any problems. It
370+ may be removed or replaced by more fine-grained arguments in future releases.
370371
371372Using convenience methods
372373-------------------------
373374While ``pyfakefs `` can be used just with the standard Python file system
374375functions, there are few convenience methods in ``fake_filesystem `` that can
375376help you setting up your tests. The methods can be accessed via the
376377``fake_filesystem `` instance in your tests: ``Patcher.fs ``, the ``fs ``
377- fixture in PyTest, or ``TestCase.fs ``.
378+ fixture in PyTest, ``TestCase.fs `` for ``unittest ``, and the ``fs `` argument
379+ for the ``patchfs `` decorator.
378380
379381File creation helpers
380382~~~~~~~~~~~~~~~~~~~~~
@@ -384,7 +386,7 @@ in the path, you may use ``create_file()``, ``create_dir()`` and
384386
385387``create_file() `` also allows you to set the file mode and the file contents
386388together with the encoding if needed. Alternatively, you can define a file
387- size without contents - in this case, you will not be able to perform
389+ size without contents-- in this case, you will not be able to perform
388390standard I\O operations on the file (may be used to "fill up" the file system
389391with large files).
390392
@@ -502,8 +504,9 @@ testing cleanup scripts), you can set the fake file system size using
502504root partition; if you add a path as parameter, the size will be related to
503505the mount point (see above) the path is related to.
504506
505- By default, the size of the fake file system is considered infinite. As soon
506- as you set a size, all files will occupy the space according to their size,
507+ By default, the size of the fake file system is set to 1 TB (which
508+ for most tests can be considered as infinite). As soon as you set a
509+ size, all files will occupy the space according to their size,
507510and you may fail to create new files if the fake file system is full.
508511
509512.. code:: python
@@ -600,9 +603,10 @@ reasons:
600603 libraries. These will not work out of the box, and we generally will not
601604 support them in `` pyfakefs`` . If these functions are used in isolated
602605 functions or classes, they may be patched by using the `` modules_to_patch``
603- parameter (see the example for file locks in Django above), and if there
604- are more examples for patches that may be useful, we may add them in the
605- documentation.
606+ parameter (see the example for file locks in Django above). We may add
607+ some of these patches to `` pyfakefs`` , so that they are applied
608+ automatically (currently done for some `` pandas`` and `` Django``
609+ functionality).
606610- It uses C libraries to access the file system. There is no way no make
607611 such a module work with `` pyfakefs`` -- if you want to use it, you
608612 have to patch the whole module. In some cases, a library implemented in
@@ -615,6 +619,11 @@ A list of Python modules that are known to not work correctly with
615619- `` multiprocessing`` has several issues (related to points 1 and 3 above).
616620 Currently there are no plans to fix this, but this may change in case of
617621 sufficient demand.
622+ - `` subprocess`` has very similar problems and cannot be used with
623+ `` pyfakefs`` to start a process. `` subprocess`` can either be mocked, if
624+ the process is not needed for the test, or patching can be paused to start
625+ a process if needed, and resumed afterwards
626+ (see `this issue < https:// github.com/ jmcgeheeiv/ pyfakefs/ issues/ 447 > ` __).
618627- the `` Pillow`` image library does not work with pyfakefs at least if writing
619628 JPEG files (see `this issue < https:// github.com/ jmcgeheeiv/ pyfakefs/ issues/ 529 > ` __)
620629- `` pandas`` (the Python data analysis library) uses its own internal file
@@ -627,6 +636,16 @@ A list of Python modules that are known to not work correctly with
627636If you are not sure if a module can be handled, or how to do it, you can
628637always write a new issue, of course!
629638
639+ Pyfakefs behaves differently than the real filesystem
640+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
641+ There are basically two kinds of deviations from the actual behavior:
642+
643+ - unwanted deviations that we didn' t notice--if you find any of these, please
644+ write an issue and will try to fix it
645+ - behavior that depends on different OS versions and editions-- as mentioned
646+ in :ref:`limitations` , pyfakefs uses the TravisCI systems as reference
647+ system and will not replicate all system- specific behavior
648+
630649OS temporary directories
631650~~~~~~~~~~~~~~~~~~~~~~~~
632651
@@ -642,13 +661,13 @@ directory named ``/tmp`` when running on Linux or Unix systems,
642661User rights
643662~~~~~~~~~~~
644663
645- If you run pyfakefs tests as root (this happens by default if run in a
646- docker container), pyfakefs also behaves as a root user, for example can
664+ If you run `` pyfakefs`` tests as root (this happens by default if run in a
665+ docker container), `` pyfakefs`` also behaves as a root user, for example can
647666write to write- protected files. This may not be the expected behavior, and
648667can be changed.
649- Pyfakefs has a rudimentary concept of user rights, which differentiates
668+ `` Pyfakefs`` has a rudimentary concept of user rights, which differentiates
650669between root user (with the user id 0 ) and any other user. By default,
651- pyfakefs assumes the user id of the current user, but you can change
670+ `` pyfakefs`` assumes the user id of the current user, but you can change
652671that using `` fake_filesystem.set_uid()`` in your setup. This allows to run
653672tests as non- root user in a root user environment and vice verse.
654673Another possibility is the convenience argument `` allow_root_user``
0 commit comments