Skip to main content

pyfakefs PyPI version Python version Testsuite Documentation Status pre-commit.ci status PyPI - Downloads

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 for more information.

Documentation

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.

Contributions

We are always grateful for meaningful contributions - refer to the contributing guide for more information. However, we value human contributions, not purly AI-generated code. The usage of AI tools is helpful and completely fine, provided that the authors use them as tools and understand what they are doing. Our policy regarding AI contributions is in line with the respective pytest policy. Please refer to that policy for details and background.

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.

Metadata

Release files for pyfakefs 6.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfakefs 6.3.0
File Size Uploaded Provenance Actions
pyfakefs-6.3.0.tar.gz 235.6 kB With provenance Details for pyfakefs-6.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyfakefs 6.3.0
File Interpreter ABI Platform Actions
pyfakefs-6.3.0-py3-none-any.whl Python 3 none any Details for pyfakefs-6.3.0-py3-none-any.whl

Total release size: 483.7 kB

Release files / pyfakefs-6.3.0.tar.gz

Download URL pyfakefs-6.3.0.tar.gz
Size 235.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b24c4922b485170cf42c00e503b7d2ef38171e23358a4b73db80a3a6ce1bbf3f
BLAKE2b-256 checksum
How to use checksums
ce93fc6ae9a1ffbe4d9a1ea657845912e150aab0c4b7da5092e696449be12439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / pyfakefs-6.3.0-py3-none-any.whl

Download URL pyfakefs-6.3.0-py3-none-any.whl
Size 248.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
176e01cf9dd484b24be7a3e33e531b1adbbf1a41262e715acee49329e9a7b6f7
BLAKE2b-256 checksum
How to use checksums
181bb857582848a21ce4497e6f1faecdd76ea38e79b42519e77665122efc511e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Security for pyfakefs 6.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyfakefs-6.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

6.3.0 This release

2 release files Full provenance

2.8

2.6

1.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page