[Python-checkins] bpo-39003: Make sure all test are the same when using -R in test_unparse (GH-17537)

Pablo Galindo webhook-mailer at python.org
Mon Dec 9 12:57:58 EST 2019


https://github.com/python/cpython/commit/ac229116a34a679511c20bfeca167cc6a9df9807
commit: ac229116a34a679511c20bfeca167cc6a9df9807
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-12-09T17:57:50Z
summary:

bpo-39003: Make sure all test are the same when using -R in test_unparse (GH-17537)

files:
M Lib/test/test_unparse.py

diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py
index 9197c8a4a9eae..96110260f550a 100644
--- a/Lib/test/test_unparse.py
+++ b/Lib/test/test_unparse.py
@@ -288,15 +288,17 @@ class DirectoryTestCase(ASTTestCase):
     test_directories = (lib_dir, lib_dir / "test")
     skip_files = {"test_fstring.py"}
 
-    @functools.cached_property
-    def files_to_test(self):
-        # bpo-31174: Use cached_property to store the names sample
-        # to always test the same files. It prevents false alarms
-        # when hunting reference leaks.
+    _files_to_test = None
+
+    @classmethod
+    def files_to_test(cls):
+
+        if cls._files_to_test is not None:
+            return cls._files_to_test
 
         items = [
             item.resolve()
-            for directory in self.test_directories
+            for directory in cls.test_directories
             for item in directory.glob("*.py")
             if not item.name.startswith("bad")
         ]
@@ -304,10 +306,15 @@ def files_to_test(self):
         # Test limited subset of files unless the 'cpu' resource is specified.
         if not test.support.is_resource_enabled("cpu"):
             items = random.sample(items, 10)
+
+        # bpo-31174: Store the names sample to always test the same files.
+        # It prevents false alarms when hunting reference leaks.
+        cls._files_to_test = items
+
         return items
 
     def test_files(self):
-        for item in self.files_to_test:
+        for item in self.files_to_test():
             if test.support.verbose:
                 print(f"Testing {item.absolute()}")
 



More information about the Python-checkins mailing list