11# pyfakefs [ ![ PyPI version] ( https://badge.fury.io/py/pyfakefs.svg )] ( https://badge.fury.io/py/pyfakefs ) [ ![ Python version] ( https://img.shields.io/pypi/pyversions/pyfakefs.svg )] ( https://img.shields.io/pypi/pyversions/pyfakefs.svg ) ![ Testsuite] ( https://github.com/pytest-dev/pyfakefs/workflows/Testsuite/badge.svg ) [ ![ Documentation Status] ( https://readthedocs.org/projects/pytest-pyfakefs/badge/?version=latest )] ( https://pytest-pyfakefs.readthedocs.io/en/latest/?badge=latest ) [ ![ pre-commit.ci status] ( https://results.pre-commit.ci/badge/github/pytest-dev/pyfakefs/main.svg )] ( https://results.pre-commit.ci/latest/github/pytest-dev/pyfakefs/main ) ![ PyPI - Downloads] ( https://img.shields.io/pypi/dw/pyfakefs )
22
33
4- pyfakefs implements a fake file system that mocks the Python file system modules.
5- Using pyfakefs, your tests operate on a fake file system in memory without
4+ ` pyfakefs ` implements a fake file system that mocks the Python file system modules.
5+ Using ` pyfakefs ` , your tests operate on a fake file system in memory without
66touching the real disk. The software under test requires no modification to
7- work with pyfakefs.
7+ work with ` pyfakefs ` .
88
9- Pyfakefs creates a new empty in-memory file system at each test start, which replaces
9+ ` pyfakefs ` creates a new empty in-memory file system at each test start, which replaces
1010the real filesystem during the test. Think of pyfakefs as making a per-test temporary
1111directory, except for an entire file system.
1212
13- There are several means to achieve this: by using
14- the ` fs ` fixture if running pytest, by using ` fake_filesystem_unittest.TestCase ` as a
15- base class if using unittest, by using a ` fake_filesystem_unittest.Patcher ` instance
16- as a context manager, or by using the ` patchfs ` decorator.
13+ ` pyfakefs ` is tested with current versions of Linux, Windows and macOS.
1714
15+ ## Usage
1816
17+ There are several ways to invoke ` pyfakefs ` :
18+ * using the ` fs ` fixture with ` pytest `
19+ * deriving from ` fake_filesystem_unittest.TestCase ` for ` unittest `
20+ * using ` fake_filesystem_unittest.Patcher ` as context manager
21+ * using the ` fake_filesystem_unittest.patchfs ` decorator on a single test
1922
20- pyfakefs works with current versions of Linux, Windows and macOS .
23+ Refer to the [ usage documentation ] ( https://pytest-pyfakefs.readthedocs.io/en/latest/usage.html ) for more information .
2124
2225## Documentation
2326
24- This document provides a general overview for pyfakefs. There is more:
25-
26- * The documentation at ** Read the Docs** :
27- * The [ Release documentation] ( https://pytest-pyfakefs.readthedocs.io/en/stable )
28- contains usage documentation for pyfakefs and a description of the
29- most relevant classes, methods and functions for the last version
30- released on PyPI
31- * The [ Development documentation] ( https://pytest-pyfakefs.readthedocs.io/en/latest )
32- contains the same documentation for the current main branch
33- * The [ Release 3.7 documentation] ( https://pytest-pyfakefs.readthedocs.io/en/v3.7.2/ )
34- contains usage documentation for the last version of pyfakefs
35- supporting Python 2.7
36- * The [ Release Notes] ( https://github.com/pytest-dev/pyfakefs/blob/main/CHANGES.md )
37- show a list of changes in the latest versions
38-
39- ## Usage
40- The simplest method to use pyfakefs is using the ` fs ` fixture with ` pytest ` .
41- Refer to the
42- [ usage documentation] ( https://pytest-pyfakefs.readthedocs.io/en/latest/usage.html )
43- for information on other test scenarios, test customization and
44- using convenience functions.
27+ * [ Release documentation] ( https://pytest-pyfakefs.readthedocs.io/en/stable )
28+ covers the latest released version
29+ * [ Development documentation] ( https://pytest-pyfakefs.readthedocs.io/en/latest )
30+ for the current main branch
31+ * [ Release 3.7 documentation] ( https://pytest-pyfakefs.readthedocs.io/en/v3.7.2/ )
32+ for the last version supporting Python 2.7
33+ * [ Release Notes] ( https://github.com/pytest-dev/pyfakefs/blob/main/CHANGES.md )
34+ * [ Contributing Guide] ( https://github.com/pytest-dev/pyfakefs/blob/main/CONTRIBUTING.md ) - contributions are welcome!
4535
4636## Features
4737Apart from automatically mocking most file-system functions, pyfakefs
@@ -54,86 +44,23 @@ provides some additional features:
5444- configuration to behave as if running as a non-root user while running
5545 under root
5646
57- ## Compatibility
58- pyfakefs works with CPython 3.7 and above, on Linux, Windows and macOS, and
59- with PyPy3.
60-
61- pyfakefs works with [ pytest] ( http://doc.pytest.org ) version 6.2.5 or above,
62- though a current version is recommended.
63-
47+ ## Limitations
6448pyfakefs will not work with Python libraries that use C libraries to access the
6549file system. This is because pyfakefs cannot patch the underlying C libraries'
6650file access functions--the C libraries will always access the real file
67- system. Refer to the
68- [ documentation] ( https://pytest-pyfakefs.readthedocs.io/en/latest/intro.html#limitations )
51+ system. Refer to the [ documentation] ( https://pytest-pyfakefs.readthedocs.io/en/latest/intro.html#limitations )
6952for more information about the limitations of pyfakefs.
7053
71- ## Development
72-
73- ### Continuous integration
74-
75- pyfakefs is currently automatically tested on Linux, macOS and Windows, with
76- Python 3.7 to 3.13, and with PyPy3 on Linux, using
77- [ GitHub Actions] ( https://github.com/pytest-dev/pyfakefs/actions ) .
78-
79- ### Running pyfakefs unit tests
80-
81- #### On the command line
82- pyfakefs unit tests can be run using ` pytest ` (all tests) or ` unittest `
83- (all tests except ` pytest ` -specific ones):
84-
85- ``` bash
86- $ cd pyfakefs/
87- $ export PYTHONPATH=$PWD
88-
89- $ python -m pytest pyfakefs
90- $ python -m pyfakefs.tests.all_tests
91- ```
92-
93- Similar scripts are called by ` tox ` and Github Actions. ` tox ` can be used to
94- run tests locally against supported python versions:
95-
96- ``` bash
97- $ tox
98- ```
99-
100- #### In a Docker container
101-
102- The ` Dockerfile ` at the repository root will run the tests on the latest
103- Ubuntu version. Build the container:
104- ``` bash
105- cd pyfakefs/
106- docker build -t pyfakefs .
107- ```
108- Run the unit tests in the container:
109- ``` bash
110- docker run -t pyfakefs
111- ```
112-
113- ### Contributing to pyfakefs
114-
115- We always welcome contributions to the library. Check out the
116- [ Contributing Guide] ( https://github.com/pytest-dev/pyfakefs/blob/main/CONTRIBUTING.md )
117- for more information.
118-
11954## History
12055pyfakefs.py was initially developed at Google by Mike Bland as a modest fake
12156implementation of core Python modules. It was introduced to all of Google
122- in September 2006. Since then, it has been enhanced to extend its
123- functionality and usefulness. At last count, pyfakefs was used in over 20,000
57+ in September 2006. At last count, pyfakefs was used in over 20,000
12458Python tests at Google.
12559
126- Google released pyfakefs to the public in 2011 as Google Code project
127- [ pyfakefs] ( http://code.google.com/p/pyfakefs/ ) :
128- * Fork
129- [ jmcgeheeiv-pyfakefs] ( http://code.google.com/p/jmcgeheeiv-pyfakefs/ ) added
130- [ direct support for unittest and doctest] ( ../../wiki/Automatically-find-and-patch-file-functions-and-modules )
131- * Fork
132- [ shiffdane-jmcgeheeiv-pyfakefs] ( http://code.google.com/p/shiffdane-jmcgeheeiv-pyfakefs/ )
133- added further corrections
134-
135- After the [ shutdown of Google Code] ( http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html )
60+ Google released pyfakefs to the public in 2011 as a Google Code project.
61+ Support for ` unittest ` and ` doctest ` was added in a fork by user ` jmcgeheeiv ` ,
62+ further corrections were made in a separate fork with user ` shiffdane ` , and after
63+ the [ shutdown of Google Code] ( http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html )
13664was announced, [ John McGehee] ( https://github.com/jmcgeheeiv ) merged all three Google Code projects together
137- [ here on GitHub] ( https://github.com/pytest-dev/pyfakefs ) where an enthusiastic community actively supports, maintains
138- and extends pyfakefs. In 2022, the repository has been transferred to
65+ [ here on GitHub] ( https://github.com/pytest-dev/pyfakefs ) . In 2022, the repository has been transferred to
13966[ pytest-dev] ( https://github.com/pytest-dev ) to ensure continuous maintenance.
0 commit comments