Closes issue 16709. unittest test discovery sorts test files for consistent test ordering

This commit is contained in:
Michael Foord 2013-03-18 17:50:12 -07:00
parent 7f6d79721d
commit 80cbc9e998
4 changed files with 17 additions and 3 deletions

View file

@ -177,6 +177,9 @@ class TestLoader(object):
The pattern is deliberately not stored as a loader attribute so that
packages can continue discovery themselves. top_level_dir is stored so
load_tests does not need to pass this argument in to loader.discover().
Paths are sorted before being imported to ensure reproducible execution
order even on filesystems with non-alphabetical ordering like ext3/4.
"""
set_implicit_top = False
if top_level_dir is None and self._top_level_dir is not None:
@ -253,7 +256,7 @@ class TestLoader(object):
def _find_tests(self, start_dir, pattern):
"""Used by discovery. Yields test suites it loads."""
paths = os.listdir(start_dir)
paths = sorted(os.listdir(start_dir))
for path in paths:
full_path = os.path.join(start_dir, path)