Skip to content

[3.6] bpo-31174: Improve the code of test_tools.test_unparse. (GH-4146) #4148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Lib/test/test_tools/test_unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ class DirectoryTestCase(ASTTestCase):
# test directories, relative to the root of the distribution
test_directories = 'Lib', os.path.join('Lib', 'test')

def get_names(self):
if DirectoryTestCase.NAMES is not None:
return DirectoryTestCase.NAMES
@classmethod
def get_names(cls):
if cls.NAMES is not None:
return cls.NAMES

names = []
for d in self.test_directories:
for d in cls.test_directories:
test_dir = os.path.join(basepath, d)
for n in os.listdir(test_dir):
if n.endswith('.py') and not n.startswith('bad'):
Expand All @@ -282,10 +283,9 @@ def get_names(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

# bpo-31174: Store the names sample to always test the same files.
# It prevents false alarms when hunting reference leaks.
cls.NAMES = names
return names

def test_files(self):
Expand Down