From ea95333daa282f401562478b04f60a5870ec27c9 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Wed, 12 Apr 2023 20:44:19 +0200 Subject: [PATCH] Make sure a /tmp path exists under linux - TMPDIR may point elsewhere - fixes #810 --- CHANGES.md | 2 ++ docs/troubleshooting.rst | 8 ++++++-- pyfakefs/fake_filesystem_unittest.py | 4 ++-- pyfakefs/tests/fake_filesystem_unittest_test.py | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 797f0850..4ece981f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,8 @@ The released versions correspond to PyPI releases. * Some public constants in `fake_filesystem` that had been moved to `helpers` are made accessible from there again (see [#809](../../issues/809)). * Add missing fake implementations for `os.getuid` and `os.getgid` (Posix only) +* Make sure a `/tmp` path exists under linux (`TMPDIR` may point elsewhere) + (see [#810](../../issues/810)) ## [Version 5.2.1](https://pypi.python.org/pypi/pyfakefs/5.2.1) (2023-04-11) diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst index 1608dec1..5f0f0cf1 100644 --- a/docs/troubleshooting.rst +++ b/docs/troubleshooting.rst @@ -170,8 +170,12 @@ directory named ``/tmp`` when running on Linux or Unix systems, # the temp directory is always present at test start assert len(os.listdir("/")) == 1 -Under macOS, a symlink to the actual temp directory is created additionally as `/tmp` -in the fake filesystem. +Under macOS and linux, if the actual temp path is not `/tmp` (which is always the case +under macOS), a symlink to the actual temp directory is additionally created as `/tmp` +in the fake filesystem. Note that the file size of this link is ignored while +calculating the fake filesystem size, so that the used size with an otherwise empty +fake filesystem can always be assumed to be 0. + User rights ----------- diff --git a/pyfakefs/fake_filesystem_unittest.py b/pyfakefs/fake_filesystem_unittest.py index 8036ab2e..00831b68 100644 --- a/pyfakefs/fake_filesystem_unittest.py +++ b/pyfakefs/fake_filesystem_unittest.py @@ -895,8 +895,8 @@ def setUp(self, doctester: Any = None) -> None: # so we create it here for convenience assert self.fs is not None self.fs.create_dir(temp_dir) - if sys.platform == "darwin" and not self.fs.exists("/tmp"): - # under macOS, we also create a link in /tmp for convenience + if sys.platform != "win32" and not self.fs.exists("/tmp"): + # under Posix, we also create a link in /tmp if the path does not exist self.fs.create_symlink("/tmp", temp_dir) # reset the used size to 0 to avoid having the link size counted # which would make disk size tests more complicated diff --git a/pyfakefs/tests/fake_filesystem_unittest_test.py b/pyfakefs/tests/fake_filesystem_unittest_test.py index 52342388..f77677c3 100644 --- a/pyfakefs/tests/fake_filesystem_unittest_test.py +++ b/pyfakefs/tests/fake_filesystem_unittest_test.py @@ -662,7 +662,7 @@ def testTempDirExists(self): @unittest.skipIf(sys.platform == "win32", "POSIX only test") def testTmpExists(self): - # directory under Linux, link under macOS + # directory or link under Linux, link under macOS self.assertTrue(os.path.exists("/tmp"))