Robert Brewer avatar Robert Brewer committed 4cadda2

2.x backports: [1389] Fix for #481 (buildbot quiet mode). Use test.py --dumb to suppress the interactive test output features, as well as the "hit enter" prompt at the end. Also [1392] Final fix for #481 (buildbot). The test suite now exits with a non-zero code if any of the tests fail.

Comments (0)

Files changed (3)

cherrypy/test/helper.py

     of test modules. The config, however, is reset for each module.
     """
     setConfig(conf)
+    # The Pybots automatic testing system needs the suite to exit
+    # with a non-zero value if there were any problems.
+    # Might as well stick it in the server... :/
+    cherrypy.server.test_success = True
     cherrypy.server.start_with_callback(_run_test_suite_thread,
                                         args = (moduleNames, conf),
                                         server_class = server)
+    if cherrypy.server.test_success:
+        return 0
+    else:
+        return 1
 
 def _run_test_suite_thread(moduleNames, conf):
     for testmod in moduleNames:
             setup()
         
         suite = CPTestLoader.loadTestsFromName(testmod)
-        CPTestRunner.run(suite)
+        result = CPTestRunner.run(suite)
+        cherrypy.server.test_success &= result.wasSuccessful()
         
         teardown = getattr(m, "teardown_server", None)
         if teardown:

cherrypy/test/modpy.py

     def _run(self, conf):
         import webtest
         webtest.WebCase.PORT = self.port
+        webtest.WebCase.interactive = self.interactive
         print
         print "Running tests:", self.server
         
         # started separately for each test, and then *that* process
         # must run the setup_server() function for the test.
         # Then our process can run the actual test.
+        test_success = True
         for testmod in self.tests:
             try:
                 start(testmod, self.port)
                 suite = webtest.ReloadingTestLoader().loadTestsFromName(testmod)
-                webtest.TerseTestRunner(verbosity=2).run(suite)
+                result = webtest.TerseTestRunner(verbosity=2).run(suite)
+                test_success &= result.wasSuccessful()
             finally:
                 stop()
+        if test_success:
+            return 0
+        else:
+            return 1
 
 

cherrypy/test/test.py

 class TestHarness(object):
     """A test harness for the CherryPy framework and CherryPy applications."""
     
-    def __init__(self, tests=None, server=None, protocol="HTTP/1.1", port=8000):
+    def __init__(self, tests=None, server=None, protocol="HTTP/1.1",
+                 port=8000, interactive=True):
         """Constructor to populate the TestHarness instance.
         
         tests should be a list of module names (strings).
         """
         self.protocol = protocol
         self.port = port
+        self.interactive = interactive
         self.server = server
         self.tests = tests or []
     
         baseconf.update(conf or {})
         
         baseconf['server.protocol_version'] = self.protocol
-        self._run(baseconf)
+        return self._run(baseconf)
     
     def _run(self, conf):
         # helper must be imported lazily so the coverage tool
         # and we wouldn't be able to globally override the port anymore.
         import helper
         webtest.WebCase.PORT = self.port
+        webtest.WebCase.interactive = self.interactive
         print
         print "Running tests:", self.server
-        helper.run_test_suite(self.tests, self.server, conf)
+        return helper.run_test_suite(self.tests, self.server, conf)
 
 
 class CommandLineParser(object):
                          }
     default_server = "wsgi"
     port = 8080
+    interactive = True
     
     def __init__(self, available_tests, args=sys.argv[1:]):
         """Constructor to populate the TestHarness instance.
         self.server = None
         self.protocol = "HTTP/1.1"
         
-        longopts = ['cover', 'profile', '1.1', 'help', 'basedir=', 'port=',
-                    'server=']
+        longopts = ['cover', 'profile', 'dumb', '1.1', 'help',
+                    'basedir=', 'port=', 'server=']
         longopts.extend(self.available_tests)
         try:
             opts, args = getopt.getopt(args, "", longopts)
                 self.cover = True
             elif o == "--profile":
                 self.profile = True
+            elif o == "--dumb":
+                self.interactive = False
             elif o == "--1.0":
                 self.protocol = "HTTP/1.0"
             elif o == "--basedir":
         
         print """CherryPy Test Program
     Usage:
-        test.py --server=* --port=%s --1.1 --cover --basedir=path --profile --tests**
+        test.py --server=* --port=%s --1.1 --cover --basedir=path --profile --dumb --tests**
         
     """ % self.__class__.port
         print '    * servers:'
         
         print """
     
-    --port=<int>: use a port other than the default (%s)
-    --1.1: use HTTP/1.1 servers instead of default HTTP/1.0
+    --port=<int>: use a port other than the default (%s).
+    --1.1: use HTTP/1.1 servers instead of default HTTP/1.0.
     
-    --cover: turn on code-coverage tool
+    --cover: turn on the code-coverage tool.
     --basedir=path: display coverage stats for some path other than cherrypy.
     
-    --profile: turn on profiling tool
+    --profile: turn on the profiling tool.
+    --dumb: turn off the interactive output features.
     """ % self.__class__.port
         
         print '    ** tests:'
         
         if self.server == 'modpy':
             import modpy
-            modpy.ModPythonTestHarness(self.tests, self.server,
-                                       self.protocol, self.port).run(conf)
+            h = modpy.ModPythonTestHarness(self.tests, self.server,
+                                           self.protocol, self.port,
+                                           self.interactive)
         else:
-            TestHarness(self.tests, self.server,
-                        self.protocol, self.port).run(conf)
+            h = TestHarness(self.tests, self.server,
+                            self.protocol, self.port,
+                            self.interactive)
+        
+        success = h.run(conf)
         
         if self.profile:
             del conf['profiling.on']
         
         if self.cover:
             self.stop_coverage()
+        
+        return success
 
 
 def prefer_parent_path():
         'test_xmlrpc_filter',
         'test_wsgiapp_filter',
     ]
-    CommandLineParser(testList).run()
-    
-    print
-    raw_input('hit enter')
+    clp = CommandLineParser(testList)
+    success = clp.run()
+    if clp.interactive:
+        print
+        raw_input('hit enter')
+    sys.exit(success)
 
 
 if __name__ == '__main__':
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 ProjectModifiedEvent.java.
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.