Skip to content

Fake directory missing on local test, but adding it breaks the pipeline with "already exists" error #789

Description

@hyler

Hey good people, I'm sorry for the seemingly bad report, I'm not sure if this is a real bug, but I'm seeing some strange behavior on macOS. I'll try to be succinct. Please assist me in delivering more information, I am new and inexperienced.

I have a method under testing that at some point does something like:

with open('/tmp/filename.txt') as f:
    ...  # Yada, yada

In my test method, I provide the fs fixture, and I make /tmp like this:

fs.create_dir('/tmp')  # Can't always rely on the OS having a real /tmp

and then I check that the file got written, etc. It all works wonderfully.

When this package is in the build pipeline (we use ADO), I get this error:

        fs.create_dir('/resources/testing')
>       fs.create_dir('/tmp')  # Can't always rely on the OS having a real /tmp
...
>       raise OSError(err_no, message, filename)
E       FileExistsError: [Errno 17] File exists in the fake filesystem: '/tmp'

However, if I remove the creation of /tmp, my local test (with python3 -m pytest) fails with the same error (which is why I added it). Furthermore, apparently the package has been building just fine in the pipeline so far without explicitly creating /tmp. (Yes, I know this implies we haven't been running pytest locally... I made changes to this package for the first time today in a long time after others had worked on it.)

I also noticed that as soon as I pass the fs fixture to my test method, calls to os.path.exists() start returning False for directories that are present on macOS, such as /usr, etc. I believe this is to be expected, since (by my logic) by providing the fs fixture I'm asking for a fake FS to "overlay" the real one.

However, I am not sure what is going on in the build pipeline. I think ADO uses Linux (either Debian or Ubuntu) to run their builds. I also have noticed that on macOS /tmp is actually a link (tmp@ -> private/tmp) but I'm not sure of the implications of that.

I can trigger the "File exists" error locally by duplicating the line:

fs.create_dir('/tmp')  # Can't always rely on the OS having a real /tmp
fs.create_dir('/tmp')  # This breaks local testing

Here are a few other details I have:

  • I'm using macOS Ventura, 13.2.1
  • I'm using Python 3.10.10 installed with Homebrew
  • I'm using pytest 7.2.2 and pyfakefs 5.0.0 (but it's the same with 5.1.0)
  • The project in question uses Python 3.9 (specifically, python:3.9-slim in the Dockerfile), but I somehow don't think this is the issue here

Anyway, any help is appreciated, this is driving me nuts. I'll be more than happy to provide you with any information you need.

Thank you!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions