def main(test_spec, should_write_xml, max_size, appengine_sdk_dir=None): fix_sys_path(appengine_sdk_dir) # This import needs to happen after fix_sys_path is run. from testutil import testsize testsize.set_max_size(max_size) if not npm.check_dependencies(): return loader = unittest.loader.TestLoader() if not os.path.exists(test_spec): suite = loader.loadTestsFromName(test_spec) elif test_spec.endswith('.py'): suite = loader.loadTestsFromName(file_path_to_module(test_spec)) else: suite = loader.discover(test_spec, pattern=TEST_FILE_RE) if should_write_xml: runner = xmlrunner.XMLTestRunner(verbose=True, output='test-reports') else: runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) return not result.wasSuccessful()
def main(test_specs, should_write_xml, max_size, appengine_sdk_dir=None): appengine_tool_setup.fix_sys_path(appengine_sdk_dir) # This import needs to happen after fix_sys_path is run. from testutil import testsize testsize.set_max_size(max_size) num_errors = 0 for test_spec in test_specs: loader = unittest.loader.TestLoader() if not os.path.exists(test_spec): suite = loader.loadTestsFromName(test_spec) elif test_spec.endswith('.py'): suite = loader.loadTestsFromName(file_path_to_module(test_spec)) else: suite = loader.discover(test_spec, pattern=TEST_FILE_RE, top_level_dir=os.getcwd()) if should_write_xml: runner = xmlrunner.XMLTestRunner(verbose=True, output='test-reports') else: runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) if not result.wasSuccessful(): num_errors += 1 return num_errors
def main(test_specs, html_basefilename, max_size, appengine_sdk_dir=None, filename=None): appengine_tool_setup.fix_sys_path(appengine_sdk_dir) # This import needs to happen after fix_sys_path is run. from testutil import testsize testsize.set_max_size(max_size) num_errors = 0 for test_spec in test_specs: loader = unittest.loader.TestLoader() if not os.path.exists(test_spec): suite = loader.loadTestsFromName(test_spec) elif test_spec.endswith('.py'): suite = loader.loadTestsFromName(file_path_to_module(test_spec)) else: suite = loader.discover(test_spec, pattern=TEST_FILE_RE, top_level_dir=os.getcwd()) if html_basefilename: import HTMLTestRunner fp = file('test_reports/%s.html' % html_basefilename, 'wb') runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='KhanLatest unit test', description='Refers to file commit %s.' % html_basefilename) runner.STYLESHEET_TMPL = '<link rel="stylesheet" href="my_stylesheet.css" type="text/css">' result = runner.run(suite) fp = file('test_reports/%s.json' % html_basefilename, "wb") json.dump({"wasSuccessful": result.wasSuccessful()}, fp) fp.close() else: runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) if not result.wasSuccessful(): num_errors += 1 return num_errors