@@ -6,75 +6,76 @@ system that mocks the Python file system modules.
6
6
Using pyfakefs, your tests operate on a fake file system in memory without touching the real disk.
7
7
The software under test requires no modification to work with pyfakefs.
8
8
9
- pyfakefs works with CPython 3.7 and above, on Linux, Windows and macOS,
9
+ `` pyfakefs `` works with CPython 3.7 and above, on Linux, Windows and macOS,
10
10
and with PyPy3.
11
11
12
- pyfakefs works with `pytest <doc.pytest.org >`__ version 3.0.0 or above by
12
+ `` pyfakefs `` works with `pytest <doc.pytest.org >`__ version 6.2.5 or above by
13
13
providing the `fs ` fixture that enables the fake filesystem.
14
14
15
15
Installation
16
16
------------
17
- pyfakefs is available on `PyPI <https://pypi.python.org/pypi/pyfakefs/ >`__.
17
+ `` pyfakefs `` is available on `PyPI <https://pypi.python.org/pypi/pyfakefs/ >`__.
18
18
The latest released version can be installed from PyPI:
19
19
20
20
.. code :: bash
21
21
22
22
pip install pyfakefs
23
23
24
- The latest main can be installed from the GitHub sources:
24
+ The latest development version ( main branch) can be installed from the GitHub sources:
25
25
26
26
.. code :: bash
27
27
28
28
pip install git+https://github.com/pytest-dev/pyfakefs
29
29
30
30
Features
31
31
--------
32
- - Code executed under pyfakefs works transparently on a memory-based file
32
+ - Code executed under `` pyfakefs `` works transparently on a memory-based file
33
33
system without the need of special commands. The same code that works on
34
34
the real filesystem will work on the fake filesystem if running under
35
- pyfakefs.
35
+ `` pyfakefs `` .
36
36
37
- - pyfakefs provides direct support for `pytest ` (via the `fs ` fixture)
37
+ - `` pyfakefs `` provides direct support for `pytest ` (via the `fs ` fixture)
38
38
and `unittest ` (via a `TestCase ` base class), but can also be used with
39
39
other test frameworks.
40
40
41
- - Each pyfakefs test starts with an empty file system, but it is possible to
42
- map files and directories from the real file system into the fake
41
+ - Each `` pyfakefs `` test starts with an empty (except for the :ref: ` os_temporary_directories `) file system,
42
+ but it is possible to map files and directories from the real file system into the fake
43
43
filesystem if needed.
44
44
45
45
- No files in the real file system are changed during the tests, even in the
46
46
case of writing to mapped real files.
47
47
48
- - pyfakefs keeps track of the filesystem size if configured. The file system
49
- size can be configured arbitrarily.
48
+ - ``pyfakefs `` keeps track of the filesystem size if configured. The file system
49
+ size can be configured arbitrarily. It is also possible to create files with a defined
50
+ size without setting contents.
50
51
51
- - it is possible to pause and resume using the fake filesystem, if the
52
- real file system has to be used in a test step
52
+ - It is possible to pause and resume using the fake filesystem, if the
53
+ real file system has to be used in a test step.
53
54
54
- - pyfakefs defaults to the OS it is running on, but can also be configured
55
+ - `` pyfakefs `` defaults to the OS it is running on, but can also be configured
55
56
to test code running under another OS (Linux, macOS or Windows).
56
57
57
- - pyfakefs can be configured to behave as if running as a root or as a
58
+ - `` pyfakefs `` can be configured to behave as if running as a root or as a
58
59
non-root user, independently from the actual user.
59
60
60
61
.. _limitations :
61
62
62
63
Limitations
63
64
-----------
64
- - pyfakefs will not work with Python libraries (other than `os ` and `io `) that
65
+ - `` pyfakefs `` will not work with Python libraries (other than `os ` and `io `) that
65
66
use C libraries to access the file system, because it cannot patch the
66
67
underlying C libraries' file access functions
67
68
68
- - pyfakefs patches most kinds of importing file system modules automatically,
69
+ - `` pyfakefs `` patches most kinds of importing file system modules automatically,
69
70
but there are still some cases where this will not work.
70
71
See :ref: `customizing_patcher ` for more information and ways to work around
71
72
this.
72
73
73
- - pyfakefs does not retain the MRO for file objects, so you cannot rely on
74
+ - `` pyfakefs `` does not retain the MRO for file objects, so you cannot rely on
74
75
checks using `isinstance ` for these objects (for example, to differentiate
75
76
between binary and textual file objects).
76
77
77
- - pyfakefs is only tested with CPython and the newest PyPy versions, other
78
+ - `` pyfakefs `` is only tested with CPython and the newest PyPy versions, other
78
79
Python implementations will probably not work
79
80
80
81
- Differences in the behavior in different Linux distributions or different
@@ -84,26 +85,30 @@ Limitations
84
85
considered as reference systems. Additionally, the tests are run in Docker
85
86
containers with the latest CentOS, Debian, Fedora and Ubuntu images.
86
87
87
- - pyfakefs may not work correctly if file system functions are patched by
88
+ - `` pyfakefs `` may not work correctly if file system functions are patched by
88
89
other means (e.g. using `unittest.mock.patch `) - see
89
90
:ref: `usage_with_mock_open ` for more information
90
91
91
- - pyfakefs will not work correctly with
92
+ - `` pyfakefs `` will not work correctly with
92
93
`behave <https://github.com/behave/behave >`__ due to the way it loads
93
94
the steps, if any filesystem modules are imported globally in the steps or
94
95
environment files; as a workaround, you may load them locally inside the
95
96
test steps (see `this issue <https://github.com/pytest-dev/pyfakefs/issues/703 >`__)
96
97
98
+ - ``pyfakefs `` is not guaranteed to work correctly in multi-threading environments.
99
+ Specifically, it does not ensure concurrent write access to a file from different
100
+ threads, which is possible under Posix.
101
+
97
102
History
98
103
-------
99
- pyfakefs was initially developed at Google by
104
+ `` pyfakefs `` was initially developed at Google by
100
105
`Mike Bland <https://mike-bland.com/about.html >`__ as a modest
101
106
fake implementation of core Python modules. It was introduced to all of
102
107
Google in September 2006. Since then, it has been enhanced to extend its
103
- functionality and usefulness. At last count, pyfakefs was used in over
108
+ functionality and usefulness. At last count, `` pyfakefs `` was used in over
104
109
20,000 Python tests at Google.
105
110
106
- Google released pyfakefs to the public in 2011 as Google Code project
111
+ Google released `` pyfakefs `` to the public in 2011 as Google Code project
107
112
`pyfakefs <http://code.google.com/p/pyfakefs/ >`__:
108
113
109
114
* Fork `jmcgeheeiv-pyfakefs <http://code.google.com/p/jmcgeheeiv-pyfakefs/ >`__
0 commit comments