Skip to content

Commit

Permalink
Make sure a /tmp path exists under linux
Browse files Browse the repository at this point in the history
- TMPDIR may point elsewhere
- fixes pytest-dev#810
  • Loading branch information
mrbean-bremen committed Apr 12, 2023
1 parent 1906fde commit 3b67fae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The released versions correspond to PyPI releases.
### Fixes
* The test fixture is now included in the source distribution and installed
with the package.
* 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)
Support for latest Python 3.12 version.
Expand Down
8 changes: 6 additions & 2 deletions docs/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand Down
4 changes: 2 additions & 2 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyfakefs/tests/fake_filesystem_unittest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))


Expand Down

0 comments on commit 3b67fae

Please sign in to comment.