1Introduction
2============
3
4`pyfakefs <https://github.com/jmcgeheeiv/pyfakefs>`__ implements a fake file
5system that mocks the Python file system modules.
6Using pyfakefs, your tests operate on a fake file system in memory without touching the real disk.
7The software under test requires no modification to work with pyfakefs.
8
9pyfakefs works with CPython 3.5 and above, on Linux, Windows and OSX
10(MacOS), and with PyPy3.
11
12pyfakefs works with `PyTest <doc.pytest.org>`__ version 2.8.6 or above.
13
14Installation
15------------
16pyfakefs is available on `PyPi <https://pypi.python.org/pypi/pyfakefs/>`__.
17The latest released version can be installed from pypi:
18
19.. code:: bash
20
21   pip install pyfakefs
22
23The latest master can be installed from the GitHub sources:
24
25.. code:: bash
26
27   pip install git+https://github.com/jmcgeheeiv/pyfakefs
28
29Features
30--------
31- Code executed under pyfakefs works transparently on a memory-based file
32  system without the need of special commands. The same code that works on
33  the real filesystem will work on the fake filesystem if running under
34  pyfakefs.
35
36- pyfakefs provides direct support for `unittest` (via a `TestCase` base
37  class) and `pytest` (via a fixture), but can also be used with other test
38  frameworks.
39
40- Each pyfakefs test starts with an empty file system, but it is possible to
41  map files and directories from the real file system into the fake
42  filesystem if needed.
43
44- No files in the real file system are changed during the tests, even in the
45  case of writing to mapped real files.
46
47- pyfakefs keeps track of the filesystem size if configured. The file system
48  size can be configured arbitrarily.
49
50- pyfakefs defaults to the OS it is running on, but can also be configured
51  to test code running under another OS (Linux, MacOS or Windows).
52
53- pyfakefs can be configured to behave as if running as a root or as a
54  non-root user, independently from the actual user.
55
56
57Limitations
58-----------
59- pyfakefs will not work with Python libraries (other than `os` and `io`) that
60  use C libraries to access the file system, because it cannot patch the
61  underlying C libraries' file access functions.
62
63- pyfakefs patches most kinds of importing file system modules automatically,
64  but there are still some cases where this will not work.
65  See :ref:`customizing_patcher` for more information and ways to work around
66  this.
67
68- pyfakefs does not retain the MRO for file objects, so you cannot rely on
69  checks using `isinstance` for these objects (for example, to differentiate
70  between binary and textual file objects).
71
72- pyfakefs is only tested with CPython and the newest PyPy versions, other
73  Python implementations will probably not work.
74
75- Differences in the behavior in different Linux distributions or different
76  MacOS or Windows versions may not be reflected in the implementation, as
77  well as some OS-specific low-level file system behavior. The systems used
78  for automatic tests in
79  `Travis.CI <https://travis-ci.org/jmcgeheeiv/pyfakefs>`__ and
80  `AppVeyor <https://ci.appveyor.com/project/jmcgeheeiv/pyfakefs>`__ are
81  considered as reference systems.
82
83History
84-------
85pyfakefs was initially developed at Google by
86`Mike Bland <https://mike-bland.com/about.html>`__ as a modest
87fake implementation of core Python modules. It was introduced to all of
88Google in September 2006. Since then, it has been enhanced to extend its
89functionality and usefulness. At last count, pyfakefs was used in over
902,000 Python tests at Google.
91
92Google released pyfakefs to the public in 2011 as Google Code project
93`pyfakefs <http://code.google.com/p/pyfakefs/>`__:
94
95* Fork `jmcgeheeiv-pyfakefs <http://code.google.com/p/jmcgeheeiv-pyfakefs/>`__
96  added direct support for unittest and doctest as described in
97  :ref:`auto_patch`
98* Fork `shiffdane-jmcgeheeiv-pyfakefs <http://code.google.com/p/shiffdane-jmcgeheeiv-pyfakefs/>`__
99  added further corrections
100
101After the `shutdown of Google
102Code <http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html>`__
103was announced, `John McGehee <https://github.com/jmcgeheeiv>`__ merged
104all three Google Code projects together `on
105GitHub <https://github.com/jmcgeheeiv/pyfakefs>`__ where an enthusiastic
106community actively maintains and extends pyfakefs.
107