@@ -266,6 +266,30 @@ passed before the ``mocker`` fixture to ensure this:
266
266
# works correctly
267
267
mocker.patch(" builtins.open" , mocker.mock_open(read_data = " content" ))
268
268
269
+ tmp_path fixture with pyfakefs
270
+ ------------------------------
271
+ If you are using the ``tmp_path `` fixture, or a similar pytest fixture
272
+ relying on the real filesystem, you may have the opposite problem: now the ``fs ``
273
+ fixture must be added *after * the ``tmp_path `` fixture. Otherwise, the path will be
274
+ created in the fake filesystem, and pytest will later try to access it in the real
275
+ filesystem.
276
+
277
+ .. code :: python
278
+
279
+ def test_working (tmp_path , fs ):
280
+ fs.create_file(tmp_path / " foo" )
281
+
282
+
283
+ def test_not_working (fs , tmp_path ):
284
+ # causes an error while pytest tries to access the temporary directory
285
+ pass
286
+
287
+ Note though that ``tmp_path `` and similar fixtures may not make much sense in the
288
+ first place if used with ``pyfakefs ``. While the directory will be created and
289
+ removed in the real filesystem, all files you create will live in the fake filesystem
290
+ only. You could as well use hardcoded paths in your tests, as they will not interfere
291
+ with paths created in other tests.
292
+
269
293
Pathlib.Path objects created outside of tests
270
294
---------------------------------------------
271
295
A pattern which is seen more often with the increased usage of ``pathlib `` is the
0 commit comments