pyfakefs
Implements a fake file system that mocks the Python file system modules.
Description
# pyfakefs [](https://badge.fury.io/py/pyfakefs) [](https://img.shields.io/pypi/pyversions/pyfakefs.svg)  [](https://pytest-pyfakefs.readthedocs.io/en/latest/?badge=latest) [](https://results.pre-commit.ci/latest/github/pytest-dev/pyfakefs/main)  `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`. `pyfakefs` creates a new empty in-memory file system at each test start, which replaces the real filesystem during the test. Think of pyfakefs as making a per-test temporary directory, except for an entire file system. `pyfakefs` is tested with current versions of Linux, Windows and macOS. ## Usage There are several ways to invoke `pyfakefs`: * using the `fs` fixture with `pytest` * deriving from `fake_filesystem_unittest.TestCase` for `unittest` * using `fake_filesystem_unittest.Patcher` as context manager * using the `fake_filesystem_unittest.patchfs` decorator on a single test Refer to the [usage documentation](https://pytest-pyfakefs.readthedocs.io/en/latest/usage.html) for more information. ## Documentation * [Release documentation](https://pytest-pyfakefs.readthedocs.io/en/stable) covers the latest released version * [Development documentation](https://pytest-pyfakefs.readthedocs.io/en/latest) for the current main branch * [Release Notes](https://github.com/pytest-dev/pyfakefs/blob/main/CHANGES.md) * [Contributing Guide](https://github.com/pytest-dev/pyfakefs/blob/main/CONTRIBUTING.md) - contributions are welcome! ## Features Apart from automatically mocking most file-system functions, pyfakefs provides some additional features: - mapping files and directories from the real file system into the fake filesystem - configuration and tracking of the file system size - pause and resume of patching to be able to use the real file system inside a test step - (limited) emulation of other OSes (Linux, macOS or Windows) - configuration to behave as if running as a non-root user while running under root ## Limitations pyfakefs will not work with Python libraries that use C libraries to access the file system. This is because pyfakefs cannot patch the underlying C libraries' file access functions--the C libraries will always access the real file system. Refer to the [documentation](https://pytest-pyfakefs.readthedocs.io/en/latest/intro.html#limitations) for more information about the limitations of pyfakefs. ## History pyfakefs.py 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. At last count, pyfakefs was used in over 20,000 Python tests at Google. Google released pyfakefs to the public in 2011 as a Google Code project. Support for `unittest` and `doctest` was added in a fork by user `jmcgeheeiv`, further corrections were made in a separate fork with user `shiffdane`, and after the [shutdown of Google Code](http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html) was announced, [John McGehee](https://github.com/jmcgeheeiv) merged all three Google Code projects together [here on GitHub](https://github.com/pytest-dev/pyfakefs). In 2022, the repository has been transferred to [pytest-dev](https://github.com/pytest-dev) to ensure continuous maintenance.
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 6.2.0 | Imported from PyPI (6.2.0) | Low | 4/21/2026 |
| v6.2.0 | - changes the MRO for file wrappers - minor bugfixes - see the [release notes](https://github.com/pytest-dev/pyfakefs/blob/version-6.2/CHANGES.md#version-620-2026-04-12) for a list of changes | Medium | 4/12/2026 |
| v6.1.6 | Follow-up bugfix release for release 6.1.5. | Low | 3/18/2026 |
| v6.1.5 | Fixes a Windows-specific issue with `os.path.realpath`. | Low | 3/15/2026 |
| v6.1.4 | Fixes an incompatibility with the VCCode unittest runner. | Low | 3/4/2026 |
| v6.1.3 | Minor bugfix release. | Low | 3/1/2026 |
| v6.1.2 | Fixes a regression caused by the introduced weak references. | Low | 2/22/2026 |
| v6.1.1 | - fixes a packaging issue in latest version | Low | 2/9/2026 |
| v6.1.0 | - changes back-link references to weak references - minor bugfixes - see the [release notes](https://github.com/pytest-dev/pyfakefs/blob/version-6.1/CHANGES.md#version-610-2026-02-06) for a list of changes | Low | 2/6/2026 |
| v6.0.0 | - removes some deprecated functionality - removes support for Python < 3.10 - see the [release notes](https://github.com/pytest-dev/pyfakefs/blob/version-6.0/CHANGES.md#version-600-2025-12-21) for a list of changes | Low | 12/21/2025 |
| v5.10.2 | - fixes a problem with `pathlib.glob` in Python 3.14 | Low | 12/21/2025 |
| v5.10.1 | Bug fix release. Fixes a regression introduced in version 5.9.0 related to `shutil.copytree`. | Low | 10/27/2025 |
| v5.10.0 | - adds official support for Python 3.14 - last minor release before 6.0, which will support Python >= 3.10 | Low | 10/11/2025 |
| v5.9.3 | Fixes a utility method. | Low | 8/29/2025 |
| v5.9.2 | This is a bugfix release. It fixes the interaction with pytest to avoid unwanted side-effects. | Low | 7/30/2025 |
| v5.9.1 | This is a bugfix release: - fixes a regression in packaging in previous version (missing tests) - correct incomplete fix in previous version (not working in Python 3.9) - See the [release notes](https://github.com/pytest-dev/pyfakefs/blob/main/CHANGES.md#version-591-2025-06-23) for a list of changes. | Low | 6/23/2025 |
| v5.9.0 | Adds support for an API change in latest Python patch releases. See the [release notes](https://github.com/pytest-dev/pyfakefs/blob/version-5.9.0/CHANGES.md#version-590-2025-06-21) for a list of changes. | Low | 6/21/2025 |
| v5.8.0 | - added preliminary support for Python 3.14 - changed behavior of `FakeFilesystem.get_object()` to ignore permissions as before - fixed a regression in version 5.7.3 that could break tests under Posix in Python 3.12 - fixed a few other issues - see the [release notes](https://github.com/pytest-dev/pyfakefs/blob/main/CHANGES.md#version-580-2025-03-11) for a list of changes | Low | 3/11/2025 |
| v5.7.4 | Minor bugfix release. | Low | 1/14/2025 |
| v5.7.3 | - fixes a regression - adds workaround for recursion problem with pytest | Low | 12/15/2024 |
| v5.7.2 | Fixes some problems with patching. | Low | 12/1/2024 |
| v5.7.1 | Fixes a regression in version 5.7.0 that broke patching `fcntl`. | Low | 10/13/2024 |
| v5.7.0 | - adds official Python 3.13 support - improves OS emulation behavior - better support for `additional_skip_names` - see the [release notes](https://github.com/pytest-dev/pyfakefs/blob/main/CHANGES.md#version-570-2024-08-10) for a list of changes | Low | 10/8/2024 |
| v5.6.0 | Adds preliminary support for Python 3.13. See the [release notes](https://github.com/pytest-dev/pyfakefs/blob/main/CHANGES.md#version-560-2024-07-12) for a list of changes. | Low | 7/12/2024 |
| v5.5.0 | Deprecates the usage of the `pathlib2` and `scandir` packages, minor bug fixes. See the [release notes](https://github.com/pytest-dev/pyfakefs/blob/main/CHANGES.md#version-550-2024-05-12) for a list of changes. | Low | 5/12/2024 |
| v5.4.1 | Bugfix release - fixes a regression. | Low | 4/11/2024 |
| v5.4.0 | Improves permission handling, fixes several issues. | Low | 4/7/2024 |
| v5.3.5 | Fixes a regression. | Low | 1/30/2024 |
| v5.3.4 | This is a bugfix release (replaces 5.3.3). | Low | 1/19/2024 |
| v5.3.3 | This is a bugfix release. | Low | 1/19/2024 |
| v5.3.2 | This is a bugfix release. | Low | 11/30/2023 |
| v5.3.1 | This is mostly a bug-fixing release. | Low | 11/15/2023 |
| v5.3.0 | Adds official support for Python 3.12. | Low | 10/11/2023 |
| v5.2.4 | Fixes a rare problem on pytest shutdown. | Low | 8/18/2023 |
| v5.2.3 | Adds compatibility with PyPy 3.10 and Python 3.12. | Low | 7/10/2023 |
| v5.2.2 | Fixes a regression in 5.2.0 | Low | 4/13/2023 |
| v5.2.1 | Support for latest Python 3.12 version (alpha 7). | Low | 4/11/2023 |
| v5.2.0 | Supports current Python 3.12 version (alpha 6) | Low | 3/31/2023 |
| v5.1.0 | Class scoped fixture and preliminary Pyton 3.12 support | Low | 1/12/2023 |
| v5.0.0 | New version after the transfer to `pytest-dev`. Deprecated old API is removed. | Low | 10/9/2022 |
| v4.7.0 | Changed handling of nested fixtures and bug fixes | Low | 9/18/2022 |
| v4.6.3 | Another patch release that fixes a regression in version 4.6 | Low | 7/20/2022 |
| v4.6.2 | Patch release that fixes an error in the previous patch. | Low | 7/14/2022 |
| v4.6.1 | Fixes incompatibility with Python 3.11 beta 4. | Low | 7/13/2022 |
| v4.6.0 | - adds support for Python 3.11 - removes support for Python 3.6 - changes root path behavior under Windows | Low | 7/12/2022 |
| v4.5.6 | Fixes a regression which broke tests with older pytest versions (< 3.9). | Low | 3/17/2022 |
| v4.5.5 | Bugfix release, needed for compatibility with pytest 7.0. | Low | 2/14/2022 |
| v4.5.4 | Minor bugfix release. | Low | 1/12/2022 |
| v4.5.3 | Reverts a change in the previous release that could cause a regression. | Low | 11/8/2021 |
| v4.5.2 | This is a bugfix release. | Low | 11/7/2021 |
| v4.5.1 | This is a bugfix release. | Low | 8/29/2021 |
