@@ -87,18 +87,49 @@ Limitations
87
87
88
88
- ``pyfakefs `` may not work correctly if file system functions are patched by
89
89
other means (e.g. using `unittest.mock.patch `) - see
90
- :ref: `usage_with_mock_open ` for more information
90
+ :ref: `usage_with_mock_open ` for more information.
91
91
92
92
- ``pyfakefs `` will not work correctly with
93
93
`behave <https://github.com/behave/behave >`__ due to the way it loads
94
94
the steps, if any filesystem modules are imported globally in the steps or
95
95
environment files; as a workaround, you may load them locally inside the
96
- test steps (see `this issue <https://github.com/pytest-dev/pyfakefs/issues/703 >`__)
96
+ test steps (see `this issue <https://github.com/pytest-dev/pyfakefs/issues/703 >`__).
97
97
98
98
- ``pyfakefs `` is not guaranteed to work correctly in multi-threading environments.
99
99
Specifically, it does not ensure concurrent write access to a file from different
100
100
threads, which is possible under Posix.
101
101
102
+
103
+ .. |br | raw :: html
104
+
105
+ <br />
106
+
107
+ Alternatives
108
+ ------------
109
+ Given the above limitations, it is not always possible to use `pyfakefs ` to emulate the
110
+ filesystem. There are other possibilities to test the filesystem that you may consider
111
+ instead, for example:
112
+
113
+ - Use temporary files in the temp directory of your OS. |br |
114
+ *Pros *: Is is relatively easy to setup new tests, and the temp files are not affecting the
115
+ functionality of the actual file system. Under POSIX systems, they are also cleaned up
116
+ periodically. |br |
117
+ *Cons *: It is slower because the actual disk is used, cleaning up after tests can be
118
+ a problem, and the filesystem lives in a fixed location, which cannot always be used
119
+ in the tested code.
120
+
121
+ - Use a RAM disk. |br |
122
+ *Pros *: It is memory-based and therefore fast, and can be set up to a clean state before
123
+ each test. |br |
124
+ *Cons *: The filesystem lives in a fixed location, which cannot always be used in the tested code.
125
+
126
+ - Use a filesystem abstraction like `PyFilesystem <https://github.com/PyFilesystem/pyfilesystem2/ >`__. |br |
127
+ *Pros *: You can replace the real filesystem by a memory based filesystem in your tests,
128
+ which has the same advantages as using ``pyfakefs ``. |br |
129
+ *Cons *: Your production code must use this abstraction, so this is more a consideration
130
+ for new projects.
131
+
132
+
102
133
History
103
134
-------
104
135
``pyfakefs `` was initially developed at Google by
0 commit comments