[PATCH] Fix sporadic test failures caused by the unstable ordering of glob.glob()

Sam Thursfield sam.thursfield at codethink.co.uk
Thu Jan 3 17:06:50 GMT 2013


glob.glob() can return results in any order. In practice it varies
at least according to the file system being used. This means that test
results may be different. To avoid this, we should always use
sorted(glob.iglob()) instead, so that the code always behaves in the
same way given the same inputs.
---
 morphlib/plugins/branch_and_merge_plugin.py |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index bba0afe..30f66ff 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -810,7 +810,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
         root_repo = self.get_branch_config(branch_path, 'branch.root')
         root_repo_dir = self.find_repository(branch_path, root_repo)
 
-        for f in glob.glob(os.path.join(root_repo_dir, '*.morph')):
+        for f in sorted(glob.iglob(os.path.join(root_repo_dir, '*.morph'))):
             name = os.path.basename(f)[:-len('.morph')]
             morphology = self.load_morphology(root_repo_dir, name)
             if morphology['kind'] != 'system':
@@ -1296,7 +1296,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
                 from_branch_dir, root_repo, from_branch,
                 to_branch_dir, root_repo, to_branch)
 
-            for f in glob.glob(os.path.join(to_root_dir, '*.morph')):
+            for f in sorted(glob.iglob(os.path.join(to_root_dir, '*.morph'))):
                 name = os.path.basename(f)[:-len('.morph')]
                 merge_system(name)
 
-- 
1.7.10.4





More information about the baserock-dev mailing list