[Python-checkins] bpo-31174: Fix test_tools.test_unparse (GH-4102) (#4104)

Victor Stinner webhook-mailer at python.org
Tue Oct 24 07:18:07 EDT 2017


https://github.com/python/cpython/commit/d8f78a1fbc0a34224289d436ad67f608fa553f0c
commit: d8f78a1fbc0a34224289d436ad67f608fa553f0c
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Victor Stinner <victor.stinner at gmail.com>
date: 2017-10-24T04:18:00-07:00
summary:

bpo-31174: Fix test_tools.test_unparse (GH-4102) (#4104)

test_unparse.DirectoryTestCase now stores the names sample to always
test the same files. It prevents false alarms when hunting reference
leaks.
(cherry picked from commit 8e482bea21cb942804234e36d3c6c896aabd32da)

files:
A Misc/NEWS.d/next/Tests/2017-10-24-11-36-10.bpo-31174.xCvXcr.rst
M Lib/test/test_tools/test_unparse.py

diff --git a/Lib/test/test_tools/test_unparse.py b/Lib/test/test_tools/test_unparse.py
index 65dee1b5ae4..bab49df3312 100644
--- a/Lib/test/test_tools/test_unparse.py
+++ b/Lib/test/test_tools/test_unparse.py
@@ -263,12 +263,14 @@ def test_dict_unpacking_in_dict(self):
 
 class DirectoryTestCase(ASTTestCase):
     """Test roundtrip behaviour on all files in Lib and Lib/test."""
+    NAMES = None
 
     # test directories, relative to the root of the distribution
     test_directories = 'Lib', os.path.join('Lib', 'test')
 
-    def test_files(self):
-        # get names of files to test
+    def get_names(self):
+        if DirectoryTestCase.NAMES is not None:
+            return DirectoryTestCase.NAMES
 
         names = []
         for d in self.test_directories:
@@ -280,6 +282,15 @@ def test_files(self):
         # Test limited subset of files unless the 'cpu' resource is specified.
         if not test.support.is_resource_enabled("cpu"):
             names = random.sample(names, 10)
+            # bpo-31174: Store the names sample to always test the same files.
+            # It prevents false alarms when hunting reference leaks.
+            DirectoryTestCase.NAMES = names
+
+        return names
+
+    def test_files(self):
+        # get names of files to test
+        names = self.get_names()
 
         for filename in names:
             if test.support.verbose:
diff --git a/Misc/NEWS.d/next/Tests/2017-10-24-11-36-10.bpo-31174.xCvXcr.rst b/Misc/NEWS.d/next/Tests/2017-10-24-11-36-10.bpo-31174.xCvXcr.rst
new file mode 100644
index 00000000000..e0980649087
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2017-10-24-11-36-10.bpo-31174.xCvXcr.rst
@@ -0,0 +1,3 @@
+Fix test_tools.test_unparse: DirectoryTestCase now stores the names sample
+to always test the same files. It prevents false alarms when hunting
+reference leaks.



More information about the Python-checkins mailing list