Implements a fake file system that mocks the Python file system modules.
Project description
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
fsfixture withpytest - deriving from
fake_filesystem_unittest.TestCaseforunittest - using
fake_filesystem_unittest.Patcheras context manager - using the
fake_filesystem_unittest.patchfsdecorator on a single test
Refer to the usage documentation for more information.
Documentation
- Release documentation covers the latest released version
- Development documentation for the current main branch
- Release 3.7 documentation for the last version supporting Python 2.7
- Release Notes
- Contributing Guide - 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 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
was announced, John McGehee merged all three Google Code projects together
here on GitHub. In 2022, the repository has been transferred to
pytest-dev to ensure continuous maintenance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfakefs-6.1.1.tar.gz.
File metadata
- Download URL: pyfakefs-6.1.1.tar.gz
- Upload date:
- Size: 226.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c166fdba85f3f288f89b2a410e05712914d1f7ea77b920e960fe0cbbea1294d
|
|
| MD5 |
7c46d335677026e194fa8ef778905544
|
|
| BLAKE2b-256 |
4384843a50cfde48d6004cbf540b38b82a39737273cc76b51da6b456fea75de0
|
Provenance
The following attestation bundles were made for pyfakefs-6.1.1.tar.gz:
Publisher:
release-deploy.yml on pytest-dev/pyfakefs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyfakefs-6.1.1.tar.gz -
Subject digest:
1c166fdba85f3f288f89b2a410e05712914d1f7ea77b920e960fe0cbbea1294d - Sigstore transparency entry: 932513728
- Sigstore integration time:
-
Permalink:
pytest-dev/pyfakefs@5514a769fa1c8ebe66791eb7d182a72cfa9b1145 -
Branch / Tag:
refs/tags/v6.1.1 - Owner: https://github.com/pytest-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-deploy.yml@5514a769fa1c8ebe66791eb7d182a72cfa9b1145 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyfakefs-6.1.1-py3-none-any.whl.
File metadata
- Download URL: pyfakefs-6.1.1-py3-none-any.whl
- Upload date:
- Size: 239.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2c30fd0b7736ba03785bbc20b86de2312623cf7a11a7de334042ab0de23d46f
|
|
| MD5 |
7d23fd684b29edc94c478689db3966d4
|
|
| BLAKE2b-256 |
a5e21d74c7663aa38e405c25a30c26e8a1b92c06f8947118b9617042f4290ade
|
Provenance
The following attestation bundles were made for pyfakefs-6.1.1-py3-none-any.whl:
Publisher:
release-deploy.yml on pytest-dev/pyfakefs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyfakefs-6.1.1-py3-none-any.whl -
Subject digest:
e2c30fd0b7736ba03785bbc20b86de2312623cf7a11a7de334042ab0de23d46f - Sigstore transparency entry: 932513788
- Sigstore integration time:
-
Permalink:
pytest-dev/pyfakefs@5514a769fa1c8ebe66791eb7d182a72cfa9b1145 -
Branch / Tag:
refs/tags/v6.1.1 - Owner: https://github.com/pytest-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-deploy.yml@5514a769fa1c8ebe66791eb7d182a72cfa9b1145 -
Trigger Event:
release
-
Statement type: