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.

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.2.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.2.0
File Size Uploaded
pyfakefs-6.2.0.tar.gz 228.3 kB Details

Built distribution (wheel)

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

Total release size: 469.4 kB

Release files / pyfakefs-6.2.0.tar.gz

Download URL pyfakefs-6.2.0.tar.gz
Size 228.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e59a36db447bf509ce9c97ab3d1510c08cc51895c5311325a560a5e5b5dc1940
BLAKE2b-256 checksum
How to use checksums
980dc80012ee6e885c293ad63c5f5b049d3ef3fd2b32bbe6fa8739145f392ec6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 12, 2026.

Transparency log

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

Download URL pyfakefs-6.2.0-py3-none-any.whl
Size 241.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0968a49db692694ffed420e54a9f1cbae4636637b880e8ab09c8ccc0f11bd7ae
BLAKE2b-256 checksum
How to use checksums
b28097571ac8295289c267367b7b60aadeae1a9a841e83f0a96ad9b65d1dd3c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

6.2.0 This release

2 release files

6.1.6

2 release files

6.1.5

2 release files

6.1.4

2 release files

6.1.3

2 release files

6.1.2

2 release files

6.1.1

2 release files

6.1.0

2 release files

6.0.0

2 release files

5.10.1

2 release files

5.10.0

2 release files

5.9.3

2 release files

5.9.2

2 release files

5.9.1

2 release files

5.9.0

2 release files

5.8.0

2 release files

5.7.4

2 release files

5.7.3

2 release files

5.7.2

2 release files

5.7.1

2 release files

5.7.0

2 release files

5.6.0

2 release files

5.5.0

2 release files

5.4.1

2 release files

5.4.0

2 release files

5.3.5

2 release files

5.3.4

2 release files

5.3.3

2 release files

5.3.2

2 release files

5.3.1

2 release files

5.3.0

2 release files

5.2.4

2 release files

5.2.3

2 release files

5.2.2

2 release files

5.2.1

2 release files

5.2.0

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.7.0

2 release files

4.6.3

2 release files

4.6.2

2 release files

4.6.1

2 release files

4.6.0

2 release files

4.5.6

2 release files

4.5.5

2 release files

4.5.4

2 release files

4.5.3

2 release files

4.5.2

2 release files

4.5.1

2 release files

4.5.0

2 release files

4.4.0

2 release files

4.3.3

2 release files

4.3.2

2 release files

4.3.1

2 release files

4.3.0

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.2

2 release files

3.7.2

2 release files

3.7.1

2 release files

3.7

2 release files

3.6.1

2 release files

3.6

2 release files

3.5.8

2 release files

3.5.7

2 release files

3.5.6

2 release files

3.5.5

2 release files

3.5.4

2 release files

3.5.3

2 release files

3.5.2

2 release files

3.5

2 release files

3.4.3

2 release files

3.4.2

1 release file

3.4.1

2 release files

3.4

2 release files

3.3

2 release files

3.2

2 release files

3.1

2 release files

3.0

1 release file

2.9

2 release files

2.8

2.7

1 release file

2.6

2.4

1 release file

2.3

1 release file

2.2

1 release file

2.1

1 release file

2.0

1 release file

1.2

1 release file

1.1

1 release file

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