Skip to content

Commit ac22911

Browse files
authored
bpo-39003: Make sure all test are the same when using -R in test_unparse (GH-17537)
1 parent c18b805 commit ac22911

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Lib/test/test_unparse.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,26 +288,33 @@ class DirectoryTestCase(ASTTestCase):
288288
test_directories = (lib_dir, lib_dir / "test")
289289
skip_files = {"test_fstring.py"}
290290

291-
@functools.cached_property
292-
def files_to_test(self):
293-
# bpo-31174: Use cached_property to store the names sample
294-
# to always test the same files. It prevents false alarms
295-
# when hunting reference leaks.
291+
_files_to_test = None
292+
293+
@classmethod
294+
def files_to_test(cls):
295+
296+
if cls._files_to_test is not None:
297+
return cls._files_to_test
296298

297299
items = [
298300
item.resolve()
299-
for directory in self.test_directories
301+
for directory in cls.test_directories
300302
for item in directory.glob("*.py")
301303
if not item.name.startswith("bad")
302304
]
303305

304306
# Test limited subset of files unless the 'cpu' resource is specified.
305307
if not test.support.is_resource_enabled("cpu"):
306308
items = random.sample(items, 10)
309+
310+
# bpo-31174: Store the names sample to always test the same files.
311+
# It prevents false alarms when hunting reference leaks.
312+
cls._files_to_test = items
313+
307314
return items
308315

309316
def test_files(self):
310-
for item in self.files_to_test:
317+
for item in self.files_to_test():
311318
if test.support.verbose:
312319
print(f"Testing {item.absolute()}")
313320

0 commit comments

Comments
 (0)