Skip to content

Commit db0d1fc

Browse files
jakesprachermrbean-bremen
authored andcommitted
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.
1 parent b59235b commit db0d1fc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/troubleshooting.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ from configuration files. In these cases, you have to map the respective files
127127
or directories from the real into the fake filesystem as described in
128128
:ref:`real_fs_access`.
129129

130+
If you are using Django, various dependencies may expect both the project
131+
directory and the ``site-packages`` installation to exist in the fake filesystem.
132+
133+
Here's an example of how to add these using pytest::
134+
135+
136+
import os
137+
import django
138+
import pytest
139+
140+
@pytest.fixture
141+
def fake_fs(fs):
142+
PROJECT_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
143+
fs.add_real_paths(
144+
[
145+
PROJECT_BASE_DIR,
146+
os.path.dirname(django.__file__),
147+
]
148+
)
149+
return fs
130150

131151
OS temporary directories
132152
------------------------

0 commit comments

Comments
 (0)