Skip to content

No such file or directory in the fake filesystem: b'/tmp' #595

@Wenzel

Description

@Wenzel

Describe the bug

pyfakefs complains that /tmp directory does not exists, despite the docs stating that "This means that any newly created fake file system will always have either a directory named /tmp when running on Linux or Unix systems"

How To Reproduce
Please have a look at this small repo:
https://github.com/Wenzel/bug_pyfakefs

smply run python -m pytest -v to reproduce the bug:

venv/lib/python3.8/site-packages/pyfakefs/fake_filesystem.py:4624: in open
    return fake_open(file, mode, buffering, encoding, errors,
venv/lib/python3.8/site-packages/pyfakefs/fake_filesystem.py:5202: in __call__
    return self.call(*args, **kwargs)
venv/lib/python3.8/site-packages/pyfakefs/fake_filesystem.py:5263: in call
    file_object = self._init_file_object(file_object,
venv/lib/python3.8/site-packages/pyfakefs/fake_filesystem.py:5330: in _init_file_object
    file_object = self.filesystem.create_file_internally(
venv/lib/python3.8/site-packages/pyfakefs/fake_filesystem.py:2608: in create_file_internally
    self.raise_os_error(errno.ENOENT, parent_directory)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pyfakefs.fake_filesystem.FakeFilesystem object at 0x7f94c2304ac0>, errno = 2, filename = b'/tmp', winerror = None

    def raise_os_error(self, errno, filename=None, winerror=None):
        """Raises OSError.
        The error message is constructed from the given error code and shall
        start with the error string issued in the real system.
        Note: this is not true under Windows if winerror is given - in this
        case a localized message specific to winerror will be shown in the
        real file system.

        Args:
            errno: A numeric error code from the C variable errno.
            filename: The name of the affected file, if any.
            winerror: Windows only - the specific Windows error code.
        """
        message = self._error_message(errno)
        if (winerror is not None and sys.platform == 'win32' and
                self.is_windows_fs):
            raise OSError(errno, message, filename, winerror)
>       raise OSError(errno, message, filename)
E       FileNotFoundError: [Errno 2] No such file or directory in the fake filesystem: b'/tmp'

venv/lib/python3.8/site-packages/pyfakefs/fake_filesystem.py:1010: FileNotFoundError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Going up in the stacktrace:
Capture d’écran de 2021-05-11 19-50-46

We see here that an error is raised because /tmp is not found.

Your environment
Please run the following and paste the output.

Linux-5.4.0-73-generic-x86_64-with-glibc2.29
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0]
pyfakefs 4.4.0

Thanks for your help !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions