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

(Optionally?) randomize arbitrary orders (e.g. listdir) #638

Closed
gsnedders opened this issue Sep 23, 2021 · 3 comments
Closed

(Optionally?) randomize arbitrary orders (e.g. listdir) #638

gsnedders opened this issue Sep 23, 2021 · 3 comments

Comments

@gsnedders
Copy link

Is your feature request related to a problem? Please describe.
This sorta is related to #151; note that at this point on CPython 3.6 and Python 3.7+ we are using an ordered dictionary type, given dict is now ordered.

But, in short, I would like to be able to test that my code doesn't rely on ordering returned by listdir.

Describe the solution you'd like
Either listdir should always shuffle its result or it should be an option when configuring pyfakefs, depending on whether we view the potential flakiness as a problem for CI systems.

Describe alternatives you've considered
I think those are both the obvious options. I guess the other option is "continue to return items in insertion order on recent Python versions", which feels like missing test coverage.

@mrbean-bremen
Copy link
Member

listdir doesn't do any ordering in pyfakefs - it makes a list from keys(), which is a set-like object, but I guess the order would still be the same in subsequent calls. So shuffling the result would slightly decrease the performance, but given that listdir won't be used too often that shouldn't really matter.
If a test depends on the order of the result of listdir it is a problem with the test, so I don't think we should make that conditional, if we change it. And, as I said, the order is already not defined now, so if a test would rely on that order, it would certainly be broken.

Looks like I just convinced myself that this would be a good idea...

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Sep 23, 2021
- makes the output order for os.listdir, `os.scandir` and `pathlib.Path.listdir` random
- see pytest-dev#638
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Sep 23, 2021
- makes the output order for os.listdir, `os.scandir` and `pathlib.Path.listdir` random
- see pytest-dev#638
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Sep 23, 2021
- makes the output order for os.listdir, `os.scandir` and `pathlib.Path.listdir` random
- see pytest-dev#638
mrbean-bremen added a commit that referenced this issue Sep 23, 2021
- makes the output order for os.listdir, `os.scandir` and `pathlib.Path.listdir` random
- see #638
@mrbean-bremen
Copy link
Member

Should work in master now.

github-actions bot pushed a commit that referenced this issue Sep 23, 2021
…der for os.listdir, `os.scandir` and `pathlib.Path.listdir` random - see #638
@mrbean-bremen
Copy link
Member

Closing as fixed - feel free to reopen if this is not what you need.

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

No branches or pull requests

2 participants