File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,10 @@ Limitations
8585 considered as reference systems, additionally the tests are run in Docker
8686 containers with the latest CentOS, Debian, Fedora and Ubuntu images.
8787
88+ - pyfakefs may not work correctly if file system functions are patched by
89+ other means (e.g. using `unittest.mock.patch `) - see
90+ :ref: `usage_with_mock_open ` for more information
91+
8892History
8993-------
9094pyfakefs was initially developed at Google by
Original file line number Diff line number Diff line change @@ -908,3 +908,19 @@ that using ``fake_filesystem.set_uid()`` in your setup. This allows to run
908908tests as non- root user in a root user environment and vice verse.
909909Another possibility to run tests as non- root user in a root user environment
910910is the convenience argument :ref:`allow_root_user` .
911+
912+ .. _usage_with_mock_open:
913+
914+ Pyfakefs and mock_open
915+ ~~~~~~~~~~~~~~~~~~~~~~
916+ If you patch `` open `` using `` mock_open`` before the initialization of
917+ `` pyfakefs`` , it will not work properly, because the `` pyfakefs``
918+ initialization relies on `` open `` working correctly.
919+ Generally, you should not need `` mock_open`` if using `` pyfakefs`` , because you
920+ always can create the files with the needed content using `` create_file`` .
921+ This is true for patching any filesystem functions - avoid patching them
922+ while working with `` pyfakefs`` .
923+ If you still want to use `` mock_open`` , make sure it is only used while
924+ patching is in progress. For example, if you are using `` pytest`` with the
925+ `` mocker`` fixture used to patch `` open `` , make sure that the `` fs`` fixture is
926+ passed before the `` mocker`` fixture to ensure this.
You can’t perform that action at this time.
0 commit comments