def run_tests(self, modules): # FIXME: implement a more useful dryrun that recurses into the test suite. if self._options.dryrun: return True # unittest has horrible error reporting when module imports are bad # so we imports them first to make debugging bad imports much easier. _log.debug("Importing all the modules to check for errors.") for module in modules: __import__(module) _log.debug("Loading the tests in the modules.") test_suite = unittest.defaultTestLoader.loadTestsFromNames(modules, None) if self._options.xml: from webkitpy.thirdparty.autoinstalled.xmlrunner import XMLTestRunner test_runner = XMLTestRunner(output='test-webkitpy-xml-reports') else: test_runner = unittest.TextTestRunner(verbosity=self._verbosity) _log.debug("Running the tests.") return test_runner.run(test_suite).wasSuccessful()
if self._is_module(dirs, name): # import modules explicitly before loading their tests because # loadTestsFromName() produces lousy error messages for bad modules. try: __import__(name) except ImportError, e: _log.fatal("Failed to import %s:" % name) self._log_exception() return False suites.append(loader.loadTestsFromName(name, None)) test_suite = unittest.TestSuite(suites) if self._options.xml: from webkitpy.thirdparty.autoinstalled.xmlrunner import XMLTestRunner test_runner = XMLTestRunner(output="test-webkitpy-xml-reports") else: test_runner = unittest.TextTestRunner(verbosity=self._verbosity) _log.debug("Running the tests.") result = test_runner.run(test_suite) if self._options.coverage: cov.stop() cov.save() return result.wasSuccessful() def _is_module(self, dirs, name): relpath = name.replace(".", os.sep) + ".py" return any(os.path.exists(os.path.join(d, relpath)) for d in dirs) def _log_exception(self):
for name in args: if self._is_module(dirs, name): # import modules explicitly before loading their tests because # loadTestsFromName() produces lousy error messages for bad modules. try: __import__(name) except ImportError, e: _log.fatal('Failed to import %s:' % name) self._log_exception() return False suites.append(loader.loadTestsFromName(name, None)) test_suite = unittest.TestSuite(suites) if self._options.xml: from webkitpy.thirdparty.autoinstalled.xmlrunner import XMLTestRunner test_runner = XMLTestRunner(output='test-webkitpy-xml-reports') else: test_runner = unittest.TextTestRunner(verbosity=self._verbosity) _log.debug("Running the tests.") result = test_runner.run(test_suite) if self._options.coverage: cov.stop() cov.save() return result.wasSuccessful() def _is_module(self, dirs, name): relpath = name.replace('.', os.sep) + '.py' return any(os.path.exists(os.path.join(d, relpath)) for d in dirs) def _log_exception(self):