Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
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
15 changes: 13 additions & 2 deletions 15 Lib/test/test_tools/test_unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to make it a static method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use a regular method, even if technically a staticmethod would work, since the method depends on the class.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the method depends on the class, make it a class method.

But in that case you should use cls.NAMES instead of DirectoryTestCase.NAMES.

if DirectoryTestCase.NAMES is not None:
return DirectoryTestCase.NAMES

names = []
for d in self.test_directories:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.