Skip to content

Commit dd22b2b

Browse files
committed
Change the default for FakeFilesystem.shuffle_listdir_results to True
- reflects the real filesystem behavior
1 parent 85720e5 commit dd22b2b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

CHANGES.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ The released versions correspond to PyPI releases.
88
these versions (usually several months after the official EOL); if the support is removed earlier
99
(as with the change to version 6), patches for previous versions are provided if requested
1010

11-
## Planned breaking changes for next major release (6.0.0)
12-
* the default for `FakeFilesystem.shuffle_listdir_results` will change to `True` to reflect
13-
the real filesystem behavior
14-
1511
## Version 6.0.0 (unreleased)
1612

1713
### Breaking Changes
1814
* removed support for Python versions < 3.10; patch releases based pyfakefs 5.10
1915
supporting older versions may be made on demand
2016
* removed support for patching legacy modules `scandir` and `pathlib2`
17+
* changed the default for `FakeFilesystem.shuffle_listdir_results` to `True` to reflect
18+
the real filesystem behavior
2119

2220
## [Version 5.10.0](https://pypi.python.org/pypi/pyfakefs/5.10.0) (2025-10-11)
2321
Adds official support for Python 3.14. Last minor version before the 6.0 release.

pyfakefs/fake_filesystem.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,12 @@ class FakeFilesystem:
190190
patch_open_code: Defines how
191191
`io.open_code <https://docs.python.org/3/library/io.html#io.open_code>`__
192192
will be patched; patching can be on, off, or in automatic mode.
193-
shuffle_listdir_results: If `True`, `os.listdir` will not sort the
194-
results to match the real file system behavior.
193+
shuffle_listdir_results: Set to `True` by default, meaning that the result order
194+
is randomized to match the real file system behavior.
195+
Setting it to `False` will cause `os.listdir` to sort the results. This is
196+
discouraged and mainly there to retain upwards compatibility - relying on
197+
the result order in tests is not recommended.
198+
This attribute may be removed in a future version.
195199
"""
196200

197201
def __init__(
@@ -265,7 +269,7 @@ def __init__(
265269

266270
# set from outside if needed
267271
self.patch_open_code = PatchMode.OFF
268-
self.shuffle_listdir_results = False
272+
self.shuffle_listdir_results = True
269273

270274
@property
271275
def is_linux(self) -> bool:
@@ -3158,8 +3162,10 @@ def listdir(self, target_directory: AnyStr) -> list[AnyStr]:
31583162
31593163
Returns:
31603164
A list of file names within the target directory in arbitrary
3161-
order. If `shuffle_listdir_results` is set, the order is not the
3162-
same in subsequent calls to avoid tests relying on any ordering.
3165+
order. Per default, the order is not the same in subsequent calls.
3166+
This can be changed by setting `shuffle_listdir_results` to `False`
3167+
for testing convenience, though is not recommended to avoid accidentally
3168+
relying on any ordering in the production code.
31633169
31643170
Raises:
31653171
OSError: if the target is not a directory.

0 commit comments

Comments
 (0)