freshcrate
Home > Frameworks > pyfakefs

pyfakefs

Implements a fake file system that mocks the Python file system modules.

Description

# pyfakefs [![PyPI version](https://badge.fury.io/py/pyfakefs.svg)](https://badge.fury.io/py/pyfakefs) [![Python version](https://img.shields.io/pypi/pyversions/pyfakefs.svg)](https://img.shields.io/pypi/pyversions/pyfakefs.svg) ![Testsuite](https://github.com/pytest-dev/pyfakefs/workflows/Testsuite/badge.svg) [![Documentation Status](https://readthedocs.org/projects/pytest-pyfakefs/badge/?version=latest)](https://pytest-pyfakefs.readthedocs.io/en/latest/?badge=latest) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/pytest-dev/pyfakefs/main.svg)](https://results.pre-commit.ci/latest/github/pytest-dev/pyfakefs/main) ![PyPI - Downloads](https://img.shields.io/pypi/dw/pyfakefs) `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

VersionChangesUrgencyDate
6.2.0Imported from PyPI (6.2.0)Low4/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 changesMedium4/12/2026
v6.1.6Follow-up bugfix release for release 6.1.5. Low3/18/2026
v6.1.5Fixes a Windows-specific issue with `os.path.realpath`.Low3/15/2026
v6.1.4Fixes an incompatibility with the VCCode unittest runner.Low3/4/2026
v6.1.3Minor bugfix release.Low3/1/2026
v6.1.2Fixes a regression caused by the introduced weak references. Low2/22/2026
v6.1.1- fixes a packaging issue in latest versionLow2/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 changesLow2/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 changesLow12/21/2025
v5.10.2- fixes a problem with `pathlib.glob` in Python 3.14Low12/21/2025
v5.10.1Bug fix release. Fixes a regression introduced in version 5.9.0 related to `shutil.copytree`.Low10/27/2025
v5.10.0- adds official support for Python 3.14 - last minor release before 6.0, which will support Python >= 3.10 Low10/11/2025
v5.9.3Fixes a utility method.Low8/29/2025
v5.9.2This is a bugfix release. It fixes the interaction with pytest to avoid unwanted side-effects.Low7/30/2025
v5.9.1This 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. Low6/23/2025
v5.9.0Adds 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.Low6/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 changesLow3/11/2025
v5.7.4Minor bugfix release.Low1/14/2025
v5.7.3- fixes a regression - adds workaround for recursion problem with pytestLow12/15/2024
v5.7.2Fixes some problems with patching.Low12/1/2024
v5.7.1Fixes a regression in version 5.7.0 that broke patching `fcntl`.Low10/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 changesLow10/8/2024
v5.6.0Adds 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.Low7/12/2024
v5.5.0Deprecates 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.Low5/12/2024
v5.4.1Bugfix release - fixes a regression.Low4/11/2024
v5.4.0Improves permission handling, fixes several issues.Low4/7/2024
v5.3.5Fixes a regression.Low1/30/2024
v5.3.4This is a bugfix release (replaces 5.3.3).Low1/19/2024
v5.3.3This is a bugfix release.Low1/19/2024
v5.3.2This is a bugfix release.Low11/30/2023
v5.3.1This is mostly a bug-fixing release.Low11/15/2023
v5.3.0Adds official support for Python 3.12.Low10/11/2023
v5.2.4Fixes a rare problem on pytest shutdown.Low8/18/2023
v5.2.3Adds compatibility with PyPy 3.10 and Python 3.12.Low7/10/2023
v5.2.2Fixes a regression in 5.2.0Low4/13/2023
v5.2.1Support for latest Python 3.12 version (alpha 7).Low4/11/2023
v5.2.0Supports current Python 3.12 version (alpha 6)Low3/31/2023
v5.1.0Class scoped fixture and preliminary Pyton 3.12 supportLow1/12/2023
v5.0.0New version after the transfer to `pytest-dev`. Deprecated old API is removed.Low10/9/2022
v4.7.0Changed handling of nested fixtures and bug fixesLow9/18/2022
v4.6.3Another patch release that fixes a regression in version 4.6Low7/20/2022
v4.6.2Patch release that fixes an error in the previous patch.Low7/14/2022
v4.6.1Fixes incompatibility with Python 3.11 beta 4.Low7/13/2022
v4.6.0- adds support for Python 3.11 - removes support for Python 3.6 - changes root path behavior under WindowsLow7/12/2022
v4.5.6Fixes a regression which broke tests with older pytest versions (< 3.9).Low3/17/2022
v4.5.5Bugfix release, needed for compatibility with pytest 7.0.Low2/14/2022
v4.5.4Minor bugfix release.Low1/12/2022
v4.5.3Reverts a change in the previous release that could cause a regression.Low11/8/2021
v4.5.2This is a bugfix release.Low11/7/2021
v4.5.1This is a bugfix release.Low8/29/2021

Dependencies & License Audit

Loading dependencies...

Similar Packages

schemathesisProperty-based testing framework for Open API and GraphQL based apps4.15.2
pytest-subtestsunittest subTest() support and subtests fixture0.15.0
seleniumbaseA complete web automation framework for end-to-end testing.4.48.2
pyhamcrestHamcrest framework for matcher objects2.1.0
pytest-httpxSend responses to httpx.0.36.2