Skip to content

Commit 15c2e57

Browse files
committed
test(tier-guard): skip the xdist probe module in the on-disk module scan (#2341)
Problem: test_every_module_resolves_to_exactly_one_tier compared suite_modules() with a bare rglob('test_*.py'), which also lists the xdist probe module while XdistSubprocessTests has it on disk. Fix: the scan moves into on_disk_test_modules(), which skips __pycache__ and _tiers.is_probe_module, as suite_modules() does. Test: ProbeModuleTests checks the scan agrees with suite_modules() with the probe on disk in a temporary tree.
1 parent bfe184b commit 15c2e57

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

‎tests/test_tier_guard.py‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ def write_module(directory: 'pathlib.Path', name: 'str', source: 'str') -> 'path
8484
return path
8585

8686

87+
def on_disk_test_modules() -> 'list[str]':
88+
"""Every ``test_*.py`` file under :file:`tests/`, relative to the root, sorted.
89+
90+
The walk :func:`~tests._tiers.suite_modules` is checked against, with the
91+
same exclusions: :file:`__pycache__` and the
92+
:func:`probe module <tests._tiers.is_probe_module>`, which
93+
:class:`tests.test_tier_guard_xdist.XdistSubprocessTests` may have on disk
94+
while the walk runs (#2341).
95+
96+
"""
97+
return sorted(path.relative_to(_tiers.ROOT).as_posix() for path in _tiers.TESTS_ROOT.rglob('test_*.py')
98+
if '__pycache__' not in path.parts and not _tiers.is_probe_module(path))
99+
100+
87101
def doctored_workflow(case: 'unittest.TestCase', old: 'str', new: 'str') -> 'pathlib.Path':
88102
"""A throwaway copy of the unit-test workflow, with ``old`` replaced by ``new``.
89103
@@ -593,8 +607,7 @@ def test_every_module_resolves_to_exactly_one_tier(self) -> None:
593607
for module in tiers[_tiers.TIER_ALL]:
594608
with self.subTest(module=module):
595609
self.assertEqual(_tiers.declared_tier(module), _tiers.TIER_ALL)
596-
found = sorted(path.relative_to(_tiers.ROOT).as_posix() for path in _tiers.TESTS_ROOT.rglob('test_*.py'))
597-
self.assertEqual(list(modules), found)
610+
self.assertEqual(list(modules), on_disk_test_modules())
598611

599612
def test_all_is_opt_in(self) -> None:
600613
"""#1963: ``ALL`` is a curated list, so only a marker puts a module in it."""
@@ -1435,6 +1448,17 @@ def test_the_probe_on_disk_is_not_a_suite_module(self) -> None:
14351448
self.assertEqual(_tiers.suite_modules(),
14361449
('tests/test_kept.py', f'tests/{_tiers.PROBE_MODULE_NAME}'))
14371450

1451+
def test_the_on_disk_scan_agrees_with_the_listing_while_the_probe_exists(self) -> None:
1452+
"""As on the Windows leg (#2341): the module-list check runs with the probe on disk.
1453+
1454+
Fails without the fix with ``First differing element 0:
1455+
'tests/protocols/test_zzz_xdist_guard_probe_unit.py'``.
1456+
1457+
"""
1458+
self.assertTrue(self.probe.exists())
1459+
self.assertEqual(on_disk_test_modules(), list(_tiers.suite_modules()))
1460+
self.assertEqual(on_disk_test_modules(), ['tests/test_kept.py'])
1461+
14381462
def test_a_probe_removed_mid_listing_does_not_break_the_tiers(self) -> None:
14391463
"""As on the Windows leg: the probe is removed between the walk and the tier read.
14401464

0 commit comments

Comments
 (0)