Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d781179

Browse files
encukousobolevn
andauthored
[3.11] gh-115421: List all test/ subdirs in Makefile, and test them (GH-115813)
This backports: - GH-115813 - GH-115422 Unlike on the main branch, new directories are added to the end, so they're a bit easier to patch out if a redistributor needs to do so. On main & 3.12, there's a special case for `idlelib/idle_test`; on 3.11 TESTSUBDIRS has several more entries that are not in `test/`. This backport ignores all of them (including idlelib). (The alternative would be list them, as additions to TEST_HOME_DIR. But that's probably too invasive; people might split stdlib up in surprising ways.) Co-authored-by: Nikita Sobolev <[email protected]>
1 parent 707ce1f commit d781179

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

Lib/test/test_tools/test_makefile.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Tests for `Makefile`.
3+
"""
4+
5+
import os
6+
import unittest
7+
from test import support
8+
import sysconfig
9+
10+
MAKEFILE = sysconfig.get_makefile_filename()
11+
12+
if not support.check_impl_detail(cpython=True):
13+
raise unittest.SkipTest('cpython only')
14+
if not os.path.exists(MAKEFILE) or not os.path.isfile(MAKEFILE):
15+
raise unittest.SkipTest('Makefile could not be found')
16+
17+
18+
class TestMakefile(unittest.TestCase):
19+
def list_test_dirs(self):
20+
result = []
21+
found_testsubdirs = False
22+
with open(MAKEFILE, 'r', encoding='utf-8') as f:
23+
for line in f:
24+
if line.startswith('TESTSUBDIRS='):
25+
found_testsubdirs = True
26+
result.append(
27+
line.removeprefix('TESTSUBDIRS=').replace(
28+
'\\', '',
29+
).strip(),
30+
)
31+
continue
32+
if found_testsubdirs:
33+
if '\t' not in line:
34+
break
35+
result.append(line.replace('\\', '').strip())
36+
37+
# In Python 3.11 (and lower), many test modules are not in
38+
# the tests/ directory. This check ignores them.
39+
result = [d for d in result if d.startswith('test/') or d == 'test']
40+
41+
return result
42+
43+
def test_makefile_test_folders(self):
44+
test_dirs = self.list_test_dirs()
45+
46+
used = []
47+
for dirpath, _, _ in os.walk(support.TEST_HOME_DIR):
48+
dirname = os.path.basename(dirpath)
49+
if dirname == '__pycache__':
50+
continue
51+
52+
relpath = os.path.relpath(dirpath, support.STDLIB_DIR)
53+
with self.subTest(relpath=relpath):
54+
self.assertIn(
55+
relpath,
56+
test_dirs,
57+
msg=(
58+
f"{relpath!r} is not included in the Makefile's list "
59+
"of test directories to install"
60+
)
61+
)
62+
used.append(relpath)
63+
64+
# Check that there are no extra entries:
65+
unique_test_dirs = set(test_dirs)
66+
self.assertSetEqual(unique_test_dirs, set(used))
67+
self.assertEqual(len(test_dirs), len(unique_test_dirs))

Makefile.pre.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,11 @@ TESTSUBDIRS= ctypes/test \
20652065
tkinter/test/test_tkinter \
20662066
tkinter/test/test_ttk \
20672067
unittest/test \
2068-
unittest/test/testmock
2068+
unittest/test/testmock \
2069+
test/test_concurrent_futures \
2070+
test/test_multiprocessing_fork \
2071+
test/test_multiprocessing_forkserver \
2072+
test/test_multiprocessing_spawn
20692073

20702074
TEST_MODULES=@TEST_MODULES@
20712075
libinstall: all $(srcdir)/Modules/xxmodule.c

0 commit comments

Comments
 (0)