Skip to content

Commit 8ae128b

Browse files
committed
Make sure a /tmp path exists under linux
- TMPDIR may point elsewhere - fixes #810
1 parent ff60173 commit 8ae128b

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The released versions correspond to PyPI releases.
1313
* Some public constants in `fake_filesystem` that had been moved to `helpers` are
1414
made accessible from there again (see [#809](../../issues/809)).
1515
* Add missing fake implementations for `os.getuid` and `os.getgid` (Posix only)
16+
* Make sure a `/tmp` path exists under linux (`TMPDIR` may point elsewhere)
17+
(see [#810](../../issues/810))
1618

1719

1820
## [Version 5.2.1](https://pypi.python.org/pypi/pyfakefs/5.2.1) (2023-04-11)

docs/troubleshooting.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,12 @@ directory named ``/tmp`` when running on Linux or Unix systems,
170170
# the temp directory is always present at test start
171171
assert len(os.listdir("/")) == 1
172172
173-
Under macOS, a symlink to the actual temp directory is created additionally as `/tmp`
174-
in the fake filesystem.
173+
Under macOS and linux, if the actual temp path is not `/tmp` (which is always the case
174+
under macOS), a symlink to the actual temp directory is additionally created as `/tmp`
175+
in the fake filesystem. Note that the file size of this link is ignored while
176+
calculating the fake filesystem size, so that the used size with an otherwise empty
177+
fake filesystem can always be assumed to be 0.
178+
175179

176180
User rights
177181
-----------

pyfakefs/fake_filesystem_unittest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,8 @@ def setUp(self, doctester: Any = None) -> None:
895895
# so we create it here for convenience
896896
assert self.fs is not None
897897
self.fs.create_dir(temp_dir)
898-
if sys.platform == "darwin" and not self.fs.exists("/tmp"):
899-
# under macOS, we also create a link in /tmp for convenience
898+
if sys.platform != "win32" and not self.fs.exists("/tmp"):
899+
# under Posix, we also create a link in /tmp if the path does not exist
900900
self.fs.create_symlink("/tmp", temp_dir)
901901
# reset the used size to 0 to avoid having the link size counted
902902
# which would make disk size tests more complicated

pyfakefs/tests/fake_filesystem_unittest_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def testTempDirExists(self):
662662

663663
@unittest.skipIf(sys.platform == "win32", "POSIX only test")
664664
def testTmpExists(self):
665-
# directory under Linux, link under macOS
665+
# directory or link under Linux, link under macOS
666666
self.assertTrue(os.path.exists("/tmp"))
667667

668668

0 commit comments

Comments
 (0)