Skip to content

Commit 3dfefdf

Browse files
committed
Fix broken test_glob_permissions test.
1 parent 734940f commit 3dfefdf

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

Lib/test/test_pathlib.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import collections.abc
23
import io
34
import os
@@ -1716,21 +1717,18 @@ def test_glob_permissions(self):
17161717
# Patching is needed to avoid relying on the filesystem
17171718
# to return the order of the files as the error will not
17181719
# happen if the symlink is the last item.
1719-
1720-
with mock.patch("os.scandir") as scandir:
1721-
scandir.return_value = sorted(os.scandir(base))
1720+
real_scandir = os.scandir
1721+
def my_scandir(path):
1722+
with real_scandir(path) as scandir_it:
1723+
entries = list(scandir_it)
1724+
entries.sort(key=lambda entry: entry.name)
1725+
return contextlib.nullcontext(entries)
1726+
1727+
with mock.patch("os.scandir", my_scandir):
17221728
self.assertEqual(len(set(base.glob("*"))), 3)
1723-
1724-
subdir.mkdir()
1725-
1726-
with mock.patch("os.scandir") as scandir:
1727-
scandir.return_value = sorted(os.scandir(base))
1729+
subdir.mkdir()
17281730
self.assertEqual(len(set(base.glob("*"))), 4)
1729-
1730-
subdir.chmod(000)
1731-
1732-
with mock.patch("os.scandir") as scandir:
1733-
scandir.return_value = sorted(os.scandir(base))
1731+
subdir.chmod(000)
17341732
self.assertEqual(len(set(base.glob("*"))), 4)
17351733

17361734
def _check_resolve(self, p, expected, strict=True):

0 commit comments

Comments
 (0)