pyfakefs 6.1.6


pip install pyfakefs

  Latest version

Released: Mar 18, 2026


Meta
Author: Google, John McGehee
Maintainer: mrbean-bremen
Requires Python: >=3.10

Classifiers

Development Status
  • 5 - Production/Stable

Environment
  • Console

Intended Audience
  • Developers

Programming Language
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Operating System
  • POSIX
  • MacOS
  • Microsoft :: Windows

Topic
  • Software Development :: Libraries
  • Software Development :: Libraries :: Python Modules
  • Software Development :: Testing
  • System :: Filesystems

Framework
  • Pytest

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.

6.1.6 Mar 18, 2026
6.1.5 Mar 15, 2026
6.1.4 Mar 04, 2026
6.1.3 Mar 01, 2026
6.1.2 Feb 22, 2026
6.1.1 Feb 09, 2026
6.1.0 Feb 06, 2026
6.0.0 Dec 21, 2025
5.10.2 Nov 04, 2025
5.10.1 Oct 27, 2025
5.10.0 Oct 11, 2025
5.9.3 Aug 29, 2025
5.9.2 Jul 30, 2025
5.9.1 Jun 23, 2025
5.9.0 Jun 21, 2025
5.8.0 Mar 11, 2025
5.7.4 Jan 14, 2025
5.7.3 Dec 15, 2024
5.7.2 Dec 01, 2024
5.7.1 Oct 13, 2024
5.7.0 Oct 08, 2024
5.6.0 Jul 12, 2024
5.5.0 May 12, 2024
5.4.1 Apr 11, 2024
5.4.0 Apr 07, 2024
5.3.5 Jan 30, 2024
5.3.4 Jan 19, 2024
5.3.3 Jan 19, 2024
5.3.2 Nov 30, 2023
5.3.1 Nov 15, 2023
5.3.0 Oct 11, 2023
5.2.4 Aug 18, 2023
5.2.3 Jul 10, 2023
5.2.2 Apr 13, 2023
5.2.1 Apr 11, 2023
5.2.0 Mar 31, 2023
5.1.0 Jan 12, 2023
5.0.0 Oct 09, 2022
4.7.0 Sep 18, 2022
4.6.3 Jul 20, 2022
4.6.2 Jul 14, 2022
4.6.1 Jul 13, 2022
4.6.0 Jul 12, 2022
4.5.6 Mar 17, 2022
4.5.5 Feb 14, 2022
4.5.4 Jan 12, 2022
4.5.3 Nov 08, 2021
4.5.2 Nov 07, 2021
4.5.1 Aug 29, 2021
4.5.0 Jun 04, 2021
4.4.0 Feb 24, 2021
4.3.3 Dec 20, 2020
4.3.2 Nov 26, 2020
4.3.1 Nov 23, 2020
4.3.0 Nov 19, 2020
4.2.1 Nov 02, 2020
4.2.0 Nov 01, 2020
4.1.0 Jul 12, 2020
4.0.2 Mar 04, 2020
3.7.2 Mar 02, 2020
3.7.1 Dec 21, 2019
3.7 Nov 24, 2019
3.6.1 Oct 07, 2019
3.6 Jun 30, 2019
3.5.8 Mar 13, 2019
3.5.7 Feb 08, 2019
3.5.6 Jan 13, 2019
3.5.5 Dec 20, 2018
3.5.4 Dec 19, 2018
3.5.3 Nov 22, 2018
3.5.2 Nov 11, 2018
3.5 Oct 22, 2018
3.4.3 Jun 13, 2018
3.4.2 Jun 13, 2018
3.4.1 Mar 18, 2018
3.4 Mar 08, 2018
3.3 Nov 12, 2017
3.2 May 27, 2017
3.1 Feb 11, 2017
3.0 Jan 31, 2017
2.9 Oct 02, 2016
2.7 Jan 14, 2016
2.4 Sep 23, 2013
2.3 Aug 27, 2013
2.2 Jun 18, 2013
2.1 May 31, 2013
2.0 May 24, 2013
1.2 May 17, 2013
1.1 May 08, 2013

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies: