Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testTmpExists fails if TMPDIR != /tmp on Linux #810

Closed
mgorny opened this issue Apr 12, 2023 · 7 comments · Fixed by #812
Closed

testTmpExists fails if TMPDIR != /tmp on Linux #810

mgorny opened this issue Apr 12, 2023 · 7 comments · Fixed by #812

Comments

@mgorny
Copy link
Contributor

mgorny commented Apr 12, 2023

Describe the bug
When TMPDIR is not /tmp (or a subdirectory of /tmp), the following test failure occurs:

======================================================================
FAIL: testTmpExists (pyfakefs.tests.fake_filesystem_unittest_test.TestTempDirCreation)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/pyfakefs/pyfakefs/tests/fake_filesystem_unittest_test.py", line 666, in testTmpExists
    self.assertTrue(os.path.exists("/tmp"))
AssertionError: False is not true

I think this is because https://github.com/pytest-dev/pyfakefs/blob/main/pyfakefs/fake_filesystem_unittest.py#L894-L903 only creates /tmp symlink on Darwin (and only TMPDIR on Linux) but https://github.com/pytest-dev/pyfakefs/blob/main/pyfakefs/tests/fake_filesystem_unittest_test.py#L663-L666 assumes /tmp on all non-win32 platforms.

How To Reproduce

export TMPDIR=/var/tmp
tox

Your environment
Please run the following in the environment where the problem happened and
paste the output.

python -c "import platform; print(platform.platform())"
python -c "import sys; print('Python', sys.version)"
python -c "from pyfakefs.fake_filesystem import __version__; print('pyfakefs', __version__)"
python -c "import pytest; print('pytest', pytest.__version__)"
Linux-6.2.10-gentoo-dist-x86_64-AMD_Ryzen_5_3600_6-Core_Processor-with-glibc2.37
Python 3.11.3 (main, Apr  6 2023, 04:25:37) [GCC 12.2.1 20230304]
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name '__version__' from 'pyfakefs.fake_filesystem' (/tmp/pyfakefs/pyfakefs/fake_filesystem.py)
pytest 7.3.0

(git 1906fde)

@mrbean-bremen
Copy link
Member

Thanks! Are you aware if there is always a /tmp dir or link under linux, so that we have do the same as under darwin? Otherwise, we just just would have to adapt the test.

@mgorny
Copy link
Contributor Author

mgorny commented Apr 12, 2023

According to FHS, /tmp must exist — and I think it'd be reasonable to assume it will exist on any Unix system, as too many scripts assume that one does exist.

(of course, using TMPDIR over /tmp [i.e. what gettempdir() returns] is preferable)

@mrbean-bremen
Copy link
Member

Ok, thanks - in this case I will just add that link also under linux. Will probably do that tonight...

@mgorny
Copy link
Contributor Author

mgorny commented Apr 12, 2023

Thanks!

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Apr 12, 2023
- TMPDIR may point elsewhere
- fixes pytest-dev#810
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Apr 13, 2023
- TMPDIR may point elsewhere
- fixes pytest-dev#810
mrbean-bremen added a commit that referenced this issue Apr 13, 2023
- TMPDIR may point elsewhere
- fixes #810
@mgorny
Copy link
Contributor Author

mgorny commented Apr 13, 2023

Thank you!

@mrbean-bremen
Copy link
Member

Thanks for the report! I will make a new patch release in a moment (because of a regression), so this will also be in the release.

@davidlbaird
Copy link
Collaborator

I think that adding new behaviors like this should be introduced through a feature flag first. There are existing unit tests and fake filesystem libraries that subclass pyfakefs that assume an empty fake file system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants