pyfakefs implements a fake file system that mocks the Python file system modules. Using pyfakefs, your tests operate on a fake file system in memory without touching the real disk. The software under test requires no modification to work with pyfakefs.

Note that pyfakefs will not work with Python libraries that use C libraries to access the file system, because it cannot patch the underlying C libraries’ file access functions.

pyfakefs works with CPython 2.6, 2.7, 3.3 and above, on Linux, Windows and OSX (MacOS), and with PyPy2 and PyPy3. Note that Python 2.6 support will be removed in the next version.

pyfakefs works with PyTest version 2.8.6 or above.


pyfakefs is available on PyPi. It can be installed using pip:

pip install pyfakefs

History was initially developed at Google by Mike Bland as a modest fake implementation of core Python modules. It was introduced to all of Google in September 2006. Since then, it has been enhanced to extend its functionality and usefulness. At last count, pyfakefs is used in over 2,000 Python tests at Google.

Google released pyfakefs to the public in 2011 as Google Code project pyfakefs:

After the shutdown of Google Code was announced, John McGehee merged all three Google Code projects together on GitHub where an enthusiastic community actively maintains and extends pyfakefs.