question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 !

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
mrbean-bremencommented, May 13, 2021

@Wenzel - shall be fixed now in master, please check!

0reactions
mrbean-bremencommented, May 14, 2021

Thanks - you are welcome!

Read more comments on GitHub >

github_iconTop Results From Across the Web

No such file or directory in the fake filesystem: b'/tmp' #595
Describe the bug pyfakefs complains that /tmp directory does not exists, despite the docs stating that "This means that any newly created ...
Read more >
pam_lastlog is complaining about corruption in /var/log/btmp file.
Mostly this corruption issue happens if filesystem where /var/log/ is mounted doesn't have enough space left. Diagnostic Steps. Check if the ...
Read more >
How do I mock the filesystem in Python unit tests?
I am mostly concerned about creating, opening and deleting files and directories. In other languages the whole file-system can be mocked. – ...
Read more >
debug1: Unable to open the btmp file /var/log/btmp: No such ...
Hello, I think it is not mandatory to have the btmp file in the tree; take for example the output of the lastb...
Read more >
Linux: /var/log/wtmp - No such file or directory quick fix and ...
Perhaps this file was removed by the operator to prevent logging last info. Then this might be a sure indicator that some malicious...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found