mock-open
A better mock for file I/O
Decision gist · record as of 2026-08-14
No. The package is abandoned (last release 2020-04-15, last commit 2020-10-10) with no maintenance or security updates. The standard library's mock.mock_open has likely evolved to address the gaps that motivated mock-open, and relying on unmaintained test infrastructure creates long-term risk. Use unittest.mock.mock_open or consider pytest-mock and related modern alternatives instead.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Installation friction is high due to source distribution format.
- The package is abandoned—last commit was 2020-10-10 and no releases since 2020-04-15—so expect no maintenance or security updates going forward.
License · maintenance · safety
MIT (permissive) — MIT license is permissive, allowing free use, modification, and distribution with minimal restrictions, suitable for both open-source and proprietary projects.
last release 2020-04-15 (2312 days) · last repo commit 2020-10-10 · 7 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 257,624 downloads/mo, #8,439 on PyPI
Alternatives
Verify before relying
from unittest.mock import patch
from mock_open import MockOpen
mock_open = MockOpen()
mock_open["/path/to/file"].read_data = "test data"
with patch("builtins.open", mock_open):
with open("/path/to/file", "r") as f:
content = f.read()- Whether the package works reliably with modern Python versions (3.9+) despite being abandoned since 2020
- Whether standard library mock.mock_open has since incorporated the features that made mock-open necessary
What it is and what it does
mock-open is a test utility that replaces the builtin open function with a mock that tracks file operations for unit testing. Unlike the standard mock.mock_open, it supports multiple file paths simultaneously, maintains file contents across separate open calls, and implements the full file API (read, write, seek, tell, readline, readlines, writelines). It's designed to let you test code that reads or writes files without touching the filesystem.
The package works by providing a MockOpen class that acts as a context manager and can be patched over builtins.open. You configure mock files by path, set their read_data or side effects, and then your code under test interacts with them as if they were real files. State persists between calls, so a write followed by a read on the same path returns what was written.
Use it for
- Test code that reads configuration files without creating temporary files on disk
- Verify file write operations in unit tests by checking mock call arguments and state
- Mock multiple file paths in a single test to simulate complex I/O scenarios
- Test error handling for file operations by setting IOError side effects on specific paths
- Ensure file operations occur in the correct order or with expected arguments
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
No.
The package is abandoned (last release 2020-04-15, last commit 2020-10-10) with no maintenance or security updates. The standard library's mock.mock_open has likely evolved to address the gaps that motivated mock-open, and relying on unmaintained test infrastructure creates long-term risk. Use unittest.mock.mock_open or consider pytest-mock and related modern alternatives instead.
Install
mock-open on PyPI
Before you install
Installation friction is high due to source distribution format. The package is abandoned—last commit was 2020-10-10 and no releases since 2020-04-15—so expect no maintenance or security updates going forward.
License in practice
MIT license is permissive, allowing free use, modification, and distribution with minimal restrictions, suitable for both open-source and proprietary projects.
Quickstart
from unittest.mock import patch
from mock_open import MockOpen
mock_open = MockOpen()
mock_open["/path/to/file"].read_data = "test data"
with patch("builtins.open", mock_open):
with open("/path/to/file", "r") as f:
content = f.read()
Verify before relying
- Whether the package works reliably with modern Python versions (3.9+) despite being abandoned since 2020
- Whether standard library mock.mock_open has since incorporated the features that made mock-open necessary
Package facts
| License | MIT permissive |
| Python support | Not specified |
| Install friction | High. Source build required |
| Runtime dependencies | None |
| Maintenance | Abandoned 2,312 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 257,624 / month, #8,439 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2.7Programming Language :: Python :: 3Topic :: Software DevelopmentTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: Software Development :: Testing |
Evidence: mock-open-1.4.0.tar.gz
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “mock file operations”
- mock-openProvides a drop-in replacement for mock.mock_open that supports…
- testpathTestpath provides utilities for testing code that interacts with…
- pytest-sftpserverA pytest plugin that provides a fixture for testing SFTP client code…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also pyfakefs · asyncmock · testfixtures · flexmock · pytest-mock · testpath · requests-file · mock · mocket · mockito