From db0d1fc97f9b51e1de6e7c782131087fadfc50ad Mon Sep 17 00:00:00 2001 From: jakespracher Date: Tue, 21 Feb 2023 10:44:43 -0500 Subject: [PATCH] Update troubleshooting to include django info As discussed on #170, we expand the troubleshooting section to include some instructions for adding pyfakefs to a django project without breaking existing tests. --- docs/troubleshooting.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst index 97d08a2f..bee2c826 100644 --- a/docs/troubleshooting.rst +++ b/docs/troubleshooting.rst @@ -127,6 +127,26 @@ from configuration files. In these cases, you have to map the respective files or directories from the real into the fake filesystem as described in :ref:`real_fs_access`. +If you are using Django, various dependencies may expect both the project +directory and the ``site-packages`` installation to exist in the fake filesystem. + +Here's an example of how to add these using pytest:: + + + import os + import django + import pytest + + @pytest.fixture + def fake_fs(fs): + PROJECT_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + fs.add_real_paths( + [ + PROJECT_BASE_DIR, + os.path.dirname(django.__file__), + ] + ) + return fs OS temporary directories ------------------------