--- id: pyfakefs version: "6.2.0" license: Apache-2.0 license_treatment: permissive maintenance: active --- # pyfakefs — Implements a fake file system that mocks the Python file system modules. License: permissive · Maintenance: active · Downloads: 4.5M/mo ## What it is and what it does pyfakefs is a testing library that replaces the real filesystem with an in-memory fake one during test execution. It automatically mocks Python's file system modules so your tests can create, read, and manipulate files without touching disk. Each test gets a fresh empty filesystem, making tests isolated and fast. The library works with unittest (via TestCase subclass or Patcher context manager) and as a decorator on individual tests. The package handles cross-platform testing by emulating Linux, Windows, and macOS filesystems, and includes features like mapping real files into the fake filesystem, tracking filesystem size, pausing/resuming patching, and simulating non-root user behavior. It does not work with libraries that use C-level filesystem access, since pyfakefs cannot patch underlying C library calls. Use it for: - Test file I/O code (reading, writing, deleting) without creating temporary files on disk - Verify error handling for missing files or permission issues in a controlled environment - Run filesystem-heavy test suites in parallel without disk contention or cleanup overhead - Test cross-platform file path logic (Windows vs. POSIX) on a single machine - Simulate full filesystem scenarios (large directory trees, disk full conditions) cheaply in memory ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. pyfakefs mocks the Python file system modules to run tests against an in-memory fake filesystem instead of the real disk, with no changes required to the code under test. Yes. pyfakefs is production-stable (Development Status 5), actively maintained, has no security vulnerabilities, and zero runtime dependencies. It solves a real testing problem—isolating filesystem operations—and is widely used. Install it if your test suite touches the filesystem. ## Install pip install pyfakefs uv add pyfakefs poetry add pyfakefs ## Installing pyfakefs Before you install: Low friction: pure Python wheel with no runtime dependencies. Actively maintained with recent releases; last commit 2026-08-13. Supports current Python versions on Linux, Windows, and macOS. License in practice: Apache-2.0 (permissive): you can use, modify, and distribute pyfakefs freely in commercial and private projects, provided you include a copy of the license and state significant changes. Quickstart: pip install pyfakefs from pyfakefs import fake_filesystem_unittest class TestWithFakeFS(fake_filesystem_unittest.TestCase): def setUp(self): self.setUpPyfakefs() def test_file_operations(self): self.fs.create_file('/tmp/test.txt', contents='hello') with open('/tmp/test.txt') as f: self.assertEqual(f.read(), 'hello') Requires Python 3.10 or later; C-based filesystem libraries cannot be mocked by pyfakefs. Verify before relying: - Performance characteristics when filesystem size grows or test count scales - Compatibility with specific C-based libraries beyond the documented limitations - Whether all test frameworks and plugins work seamlessly with pyfakefs patching ## Package facts - License: Apache-2.0 (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 4.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags mock filesystem for testing, fake file system testing, in-memory filesystem testing, file system mocking library, test file operations without disk, unittest filesystem mocking, temporary filesystem per test, test-isolation, mocking, filesystem [View on SkillFed](https://skillfed.io/packages/pyfakefs) · [View on PyPI](https://pypi.org/project/pyfakefs/)