--- id: mock-open version: "1.4.0" license: MIT license_treatment: permissive maintenance: abandoned --- # mock-open — A better mock for file I/O License: permissive · Maintenance: abandoned · Downloads: 257.6K/mo ## 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 above — verify before relying. Provides a drop-in replacement for mock.mock_open that supports multiple files, persistent file state across open calls, and standard file operations like read, write, seek, and tell. 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 pip install mock-open uv add mock-open poetry add mock-open ## Installing mock-open 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: unspecified - Install friction: high - Maintenance: abandoned - Downloads: 257.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags mock file operations, file I/O testing, mock open replacement, unit test file mocking, fake file system, mock multiple files, persistent mock files, abandoned, testing-utility [View on SkillFed](https://skillfed.io/packages/mock-open) · [View on PyPI](https://pypi.org/project/mock-open/)