Ned Batchelder avatar Ned Batchelder committed bfdbb53

test_farm will check the exist status of commands, and can leave the output for examination.

Comments (0)

Files changed (1)


 import filecmp, fnmatch, glob, os, shutil, sys
 from coverage.files import FileLocator
+    import subprocess
+except ImportError:
+    subprocess = None
 def test_farm(clean_only=False):
     """A test-generating function for nose to find and run."""
 class FarmTestCase(object):
-    def __init__(self, runpy, clean_only=False):
+    def __init__(self, runpy, clean_only=False, dont_clean=False):
         self.dir, self.runpy = os.path.split(runpy)
         self.clean_only = clean_only
+        self.dont_clean = dont_clean
     def cd(self, newdir):
         cwd = os.getcwd()
             glo['clean'] = self.clean
             glo = dict([(fn, getattr(self, fn)) for fn in fns])
+            if self.dont_clean:
+                glo['clean'] = self.noop
         execfile(self.runpy, glo)
     def fnmatch_list(self, files, filepattern):
-        """Filter the list of `files` to only those that match `filepattern`."""
+        """Filter the list of `files` to only those that match `filepattern`.
-        return [f for f in files if fnmatch.fnmatch(f, filepattern)]
+        Returns a string naming the filtered files.
+        """
+        files = [f for f in files if fnmatch.fnmatch(f, filepattern)]
+        return ", ".join(files)
     # Functions usable inside farm files
         cwd =
         for cmd in cmds.split("\n"):
-            stdin, stdouterr = os.popen4(cmd)
-            output =
+            if subprocess:
+                proc = subprocess.Popen(cmd, shell=True, 
+                          stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+                          stderr=subprocess.STDOUT)
+                retcode = proc.wait()
+                output =
+            else:
+                stdin, stdouterr = os.popen4(cmd)
+                output =
+                retcode = 0 # Can't tell if the process failed.
             print output,
+            if retcode:
+                raise Exception("command exited abnormally")
     def compare(self, dir1, dir2, filepattern=None):
 if __name__ == '__main__':
     op = sys.argv[1]
     if op == 'run':
+        # Run the test for real.
         case = FarmTestCase(sys.argv[2])
+    if op == 'out':
+        # Run the test, but don't clean up, so we can examine the output.
+        case = FarmTestCase(sys.argv[2], dont_clean=True)
+        case.execute()
     elif op == 'clean':
+        # Run all the tests, but just clean.
         for test in test_farm(clean_only=True):
-        print "Need an operation: run, clean"
+        print "Need an operation: run, out, clean"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.