]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126014: test_makefile_test_folders: Ignore basically-empty directories (#140466)
authorStefano Rivera <stefano@rivera.za.net>
Tue, 27 Jan 2026 10:05:09 +0000 (02:05 -0800)
committerGitHub <noreply@github.com>
Tue, 27 Jan 2026 10:05:09 +0000 (11:05 +0100)
The code in test_makefile was attempting to ignore any
non-interesting files, but missed some corners:

1. There is never a *file* called `__pycache__`.
2. A directory containing only a `__pycache__` subdirectory should be
   ignored.
3. A directory containing only hidden files should be ignored.

Simplify this all into a couple of filters that let us check for empty
lists.

Lib/test/test_tools/test_makefile.py

index 4c7588d4d93fc38c528186e7253b3a3f15bb9f8d..31a516067394e1e65773a290a3cddda01216e30c 100644 (file)
@@ -48,15 +48,18 @@ class TestMakefile(unittest.TestCase):
             if dirname == '__pycache__' or dirname.startswith('.'):
                 dirs.clear()  # do not process subfolders
                 continue
-            # Skip empty dirs:
+
+            # Skip empty dirs (ignoring hidden files and __pycache__):
+            files = [
+                filename for filename in files
+                if not filename.startswith('.')
+            ]
+            dirs = [
+                dirname for dirname in dirs
+                if not dirname.startswith('.') and dirname != "__pycache__"
+            ]
             if not dirs and not files:
                 continue
-            # Skip dirs with hidden-only files:
-            if files and all(
-                filename.startswith('.') or filename == '__pycache__'
-                for filename in files
-            ):
-                continue
 
             relpath = os.path.relpath(dirpath, support.STDLIB_DIR)
             with self.subTest(relpath=relpath):