@@ -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