def run_tests(): result = TestResult() print(TermColor.BOLD + 'Running tests ... ' + TermColor.ENDC, end='') defaultTestLoader.discover('.').run(result) if result.wasSuccessful(): print(TermColor.OKGREEN + 'Passed' + TermColor.ENDC) else: print(TermColor.FAIL + 'Failed' + TermColor.ENDC) print() return result.wasSuccessful()
def main(): # Configure python path parent = os.path.dirname(os.path.abspath(__file__)) if not parent in sys.path: sys.path.insert(0, parent) # Configure logging logging.basicConfig(level=logging.ERROR) # Configure setup from cio.conf import settings settings.configure(STORAGE={ 'BACKEND': 'sqlite://:memory:?foo=bar', 'NAME': '__overridden__', 'OPTIONS': { 'check_same_thread': False } }) # Run tests tests = TestLoader.discover('tests') suite = TestSuite(tests) result = TestRunner(verbosity=1, failfast=False).run(suite) exit_code = len(result.failures) + len(result.errors) sys.exit(exit_code)
def main(config_module=None): from testlinktool.main.config import TESTLINK_SERVER, TESTLINK_PROJECT_ID, TESTLINK_PROJECT_NAME,\ TESTLINK_API_KEY, CUSTOM_FIELD_NAME_LIST, UI_TEST_KEYWORD # use configuration try: if config_module is not None: TESTLINK_SERVER = getattr(config_module, "TESTLINK_SERVER") TESTLINK_PROJECT_ID = getattr(config_module, "TESTLINK_PROJECT_ID") TESTLINK_PROJECT_NAME = getattr(config_module, "TESTLINK_PROJECT_NAME") TESTLINK_API_KEY = getattr(config_module, "TESTLINK_API_KEY") CUSTOM_FIELD_NAME_LIST = getattr(config_module, "CUSTOM_FIELD_NAME_LIST") UI_TEST_KEYWORD = getattr(config_module, "UI_TEST_KEYWORD") elif exists(join(getcwd(), 'config.json')): with open(join(getcwd(), 'config.json')) as j_file: conf_dic = json_read_file(j_file) TESTLINK_SERVER = conf_dic["TESTLINK_SERVER"] TESTLINK_PROJECT_ID = conf_dic["TESTLINK_PROJECT_ID"] TESTLINK_PROJECT_NAME = conf_dic["TESTLINK_PROJECT_NAME"] TESTLINK_API_KEY = conf_dic["TESTLINK_API_KEY"] CUSTOM_FIELD_NAME_LIST = conf_dic["CUSTOM_FIELD_NAME_LIST"] UI_TEST_KEYWORD = conf_dic["UI_TEST_KEYWORD"] except ImportError: print("Warning we are using default parameters") parser = argparse.ArgumentParser(description='') group = parser.add_argument_group() group.add_argument('-d', '--test-dir', dest='dest_dir', help="The directory path where generated tests will be sent (defaults to 'tests')", default="tests") group.add_argument('-p', '--plan', dest='plan', help="the test plan", default=None, required=True) group.add_argument('-a', '--download-all', dest='download_all', default=False, action="store_true", help="if used will download all tests, even those which are already coded") group.add_argument('-v', '--verbose', dest='verbose', default=False, action="store_true", help="verbosity") args = parser.parse_args() tl_helper = TestLinkHelper(TESTLINK_SERVER, TESTLINK_API_KEY) testlink_client = tl_helper.connect(TestlinkAPIClient) plan_id = int(testlink_client.getTestPlanByName(TESTLINK_PROJECT_NAME, args.plan)[0]['id']) suites = testlink_client.getTestSuitesForTestPlan(plan_id) # build a id/name relation dictionary suites_tc_dic = { suite["id"]: suite["name"] for suite in suites } cases = get_tests(testlink_client, UI_TEST_KEYWORD, plan_id, TESTLINK_PROJECT_ID, CUSTOM_FIELD_NAME_LIST) names = [n["tcase_name"] for n in cases] other_cases = get_tests(testlink_client, None, plan_id, TESTLINK_PROJECT_ID, CUSTOM_FIELD_NAME_LIST) cases += [n for n in other_cases if n["tcase_name"] not in names] for case in cases: case["suite"] = suites_tc_dic[case["testsuite_id"]] tests = [] # if we do not force to download everythin we get already defined tests to avoid erasing them if not args.download_all: tests += list(set([a for a in get_test_names(defaultTestLoader.discover(args.dest_dir))])) # launch true creation for to_be_created in cases: if to_be_created["tcase_name"] not in tests: create_test_file(to_be_created, args.dest_dir, to_be_created["keyword"] == UI_TEST_KEYWORD, args.plan)
def runTestProcess(self): '''单个流程的执行全过程''' # 获取数据表sheet及当前执行流程调用的数据所在行 self.getDataSheet() self.setGlobalVar("TESTROW", self.dataRowInitialization()) # 初始化流程开关 loadProcessValue("#流程开关", realValue="") # 指定测试用例为当前文件夹下的 interface 目录 test_dir = './interface' testsuit = defaultTestLoader.discover(test_dir, pattern='Test_*.py') # testsuit = defaultTestLoader.discover(test_dir, pattern='*_test.py') # 初始化数据库数据 self.environment = makeJsonData("测试环境", whetherToInitialize="是") self.setGlobalVar("ENVIRONMENT", self.environment) self.init_DB(self.environment) timeStr = datetime.now() now = timeStr.strftime("%Y-%m-%d %H_%M_%S.%f") # now = time.strftime("%Y-%m-%d %H_%M_%S") filename = './report/' + now + '_result.html' fp = open(filename, 'wb') runner = HTMLTestRunner(stream=fp, title='"%s"自动化测试报告' % (self.dataSheetName.replace("数据表-", "")), description='运行环境:%s' % (self.environment)) runner.run(testsuit) fp.close() self.replayKey += 1
def test(): """ Execute your automated tests """ sys.path.append(path('src/main/python')) suite = TestSuite() test_dirs = SETTINGS['test_dirs'] for test_dir in map(path, test_dirs): sys.path.append(test_dir) try: dir_names = listdir(test_dir) except FileNotFoundError: continue for dir_name in dir_names: dir_path = join(test_dir, dir_name) if isfile(join(dir_path, '__init__.py')): suite.addTest(defaultTestLoader.discover( dir_name, top_level_dir=test_dir )) has_tests = bool(list(suite)) if has_tests: TextTestRunner().run(suite) else: print( 'No tests found. You can add them to:\n * '+ '\n * '.join(test_dirs) )
def _unittests(): from unittest import TestSuite, defaultTestLoader, TextTestRunner _tests = TestSuite() for case in defaultTestLoader.discover('.', 'test_*.py'): _tests.addTests(case) tester = TextTestRunner() tester.run(_tests)
def manualRunCase(self, **resp): for key in resp: dict_key = json.loads(key) case_list = dict_key['runningCase'] print(case_list) # 根据前端传过来的用例参数属性查找到特定用例再添加到测试集合中 for cases in case_list: project_id = cases['caseProName'] module = cases['caseModule'] api_id = cases['caseApiName'] case_dir = '\\caseSet\\%s\\%s\\%s' % (project_id, module, api_id) base_dir = os.path.dirname(os.path.realpath(__file__)) test_dir = base_dir + case_dir print(test_dir) testSuit = defaultTestLoader.discover(start_dir=test_dir, pattern='*_test.py', top_level_dir=base_dir) print(testSuit) now = time.strftime("%Y-%m-%d %H_%M_%S") filename = os.path.dirname( os.path.abspath(__file__)) + './report/' + now + '_result.html' fp = open(filename, 'wb') runner = HTMLTestRunner( stream=fp, title='接口自动化测试', description='运行环境:Python3, Sqlite3, Requests, unittest ') runner.run(testSuit) fp.close() return {'code': 200, 'msg': '执行完成'}
def load_tests(loader, tests, pattern): suite = TestSuite() for all_test_suite in defaultTestLoader.discover('.', pattern='*tests.py'): for test_suite in all_test_suite: suite.addTests(test_suite) return suite
def run_all(self): tests = defaultTestLoader.discover(self._path) testRunner = runner.TextTestRunner() result = testRunner.run(tests) sys.exit(not result.wasSuccessful())
def run_utests(): if len(sys.argv) > 1: print(__doc__) return 251 suite = defaultTestLoader.discover(join(ROOT, 'utest'), 'test_*.py') result = TextTestRunner().run(suite) return min(len(result.failures) + len(result.errors), 250)
def build_suite(self, options, extra_tests=None, **kwargs): tests = [] discovery_root = settings.TEST_DISCOVERY_ROOT test_labels = [x[0][6:] for x in os.walk(discovery_root) if x[0].count('/') == 1] if '__pycache__' in test_labels: test_labels.remove('__pycache__') test_labels = ['tests.' + label for label in test_labels] for label in test_labels: test_root = import_module(label).__path__[0] tests.extend(make_test_case(defaultTestLoader.discover( test_root, top_level_dir=settings.BASE_PATH, pattern='*.py' ))) include = [re.compile(x, re.I) for x in options if not x.startswith('no')] exclude = [re.compile(x[2:], re.I) for x in options if x.startswith('no')] tests = [(str(type(test))[14:-2], test) for test in tests] if include: tests = [t for t in tests if any([p.search(t[0]) for p in include])] for pattern in exclude: tests = [t for t in tests if not pattern.search(t[0])] suite = TestSuite([x[1] for x in tests]) if extra_tests: for test in extra_tests: suite.addTest(test) return reorder_suite(suite, (TestCase,))
def main(argv): # 主方法 pattern = 'test_*.py' # pattern默认搜集全部测试用例 env = 'test' # 默认在测试环境运行测试用例 try: opts, args = getopt.getopt(argv, 'hp:e:') for opt, arg in opts: if opt == '-h': print('run.py -p <pattern> -e <environment>') sys.exit() if opt == '-e': env = arg.lower() if opt == '-p': pattern = f'{arg}*.py' build_config(env) # 构建CONFIG文件 except getopt.GetoptError as e: print(e) sys.exit() # 根据入参pattern,在case文件夹中收集测试用例,pattern默认搜集全部测试用例 cases = defaultTestLoader.discover('./case/', pattern=pattern) # 实例化一个测试执行器并执行所有测试用例 runner = TextTestRunner() runner.run(cases)
def main(): __DIR__ = os.path.dirname(os.path.abspath(__file__)) USE_XML_RUNNER = True # target: path to the directory used to store the generated XML files. # terminal_path: path to the file used to store the standard output of the # test execution. top_directory = os.path.join(__DIR__, 'test', 'my_package') target = os.path.join(gettempdir(), 'result') terminal_path = os.path.join(gettempdir(), 'terminal') print(f'XML files will be generated under the directory "{target}".') print(f'Path to the terminal file: "{terminal_path}".') with open(terminal_path, 'w') as terminal: test_suite: TestSuite = defaultTestLoader.discover( start_dir=f'{top_directory}', top_level_dir=__DIR__, pattern='*_test.py') print(f'Number of unit tests: {test_suite.countTestCases()}') if USE_XML_RUNNER: test_result = xmlrunner.XMLTestRunner( output=target, verbosity=0, stream=terminal).run(test_suite) else: result = TestResult() test_suite.run(result) test_case: TestCase message: str for test_case, message in result.failures: print(test_case.id() + ':') print('\n'.join([f'\t{m}' for m in message.split('\n')]))
def run(): verbosity = 1 if "-v" in sys.argv or "--verbose" in sys.argv: verbosity = 2 tests = defaultTestLoader.discover(".") runner = TextTestRunner(verbosity=verbosity) result = runner.run(tests) return result.failures
def main(): suite = TestSuite() for i in defaultTestLoader.discover("cryptowelder_test", pattern="test_*.py"): suite.addTest(i) TextTestRunner().run(suite)
def run_unit_tests(): sys.path.insert(0, join(CURDIR, '..', 'src')) try: suite = defaultTestLoader.discover(join(CURDIR, 'unit'), 'test_*.py') result = TextTestRunner().run(suite) finally: sys.path.pop(0) return min(len(result.failures) + len(result.errors), 255)
def runTests( testDir, verbosity=1 ): "discover and run all tests in testDir" # ensure root and cleanup before starting tests cleanup() # discover all tests in testDir testSuite = defaultTestLoader.discover( testDir ) # run tests TextTestRunner( verbosity=verbosity ).run( testSuite )
def load_tests(loader, tests, pattern): """Returns the test modules for the mongows package. The expected output of this function is defined by the unittest module's load_tests protocol. unittest.main() will runs tests on the modules returned by this function. """ return defaultTestLoader.discover(__name__)
def runTests(testDir, verbosity=1): "discover and run all tests in testDir" # ensure root and cleanup before starting tests ensureRoot() cleanup() # discover all tests in testDir testSuite = defaultTestLoader.discover(testDir) # run tests TextTestRunner(verbosity=verbosity).run(testSuite)
def runTests(testDir, verbosity=1): "discover and run all tests in testDir" # ensure root and cleanup before starting tests ensureRoot() cleanup() # discover all tests in testDir testSuite = defaultTestLoader.discover(testDir) # run tests success = TextTestRunner(verbosity=verbosity).run(testSuite).wasSuccessful() sys.exit(0 if success else 1)
def run(self): if not self.logger.isEnabledFor(INFO): self.logger.setLevel(INFO) Test.hosts = self.hosts if len(self.params.tests) is 0: tests = defaultTestLoader.discover('tests', '*.py') else: tests = defaultTestLoader.loadTestsFromNames(self.params.tests) self.run_test(tests)
def run_tests(): """Collect and run all SAPPHiRE tests :return: `unittest.TextTestResult` object containing the test results. """ test_path = os.path.dirname(__file__) package_tests = defaultTestLoader.discover(start_dir=test_path) test_suite = TestSuite(tests=package_tests) test_result = TextTestRunner().run(test_suite) return test_result
def runTests( testDir, verbosity=1 ): "discover and run all tests in testDir" # ensure root and cleanup before starting tests ensureRoot() cleanup() # discover all tests in testDir testSuite = defaultTestLoader.discover( testDir ) # run tests success = ( TextTestRunner( verbosity=verbosity ) .run( testSuite ).wasSuccessful() ) sys.exit( 0 if success else 1 )
def main() -> None: args = parse_args() suite = defaultTestLoader.discover(_tests_, top_level_dir=_parent_, pattern=args.pattern) runner = TextTestRunner( verbosity=args.verbosity, failfast=args.fail, buffer=args.buffer, ) installHandler() runner.run(suite)
def runTests(testDir, verbosity=1, dockeronly=False): "discover and run all tests in testDir" # ensure root and cleanup before starting tests ensureRoot() cleanup() # discover all tests in testDir testSuite = defaultTestLoader.discover(testDir) if dockeronly: testSuiteFiltered = [s for s in testSuite if "Docker" in str(s)] testSuite = TestSuite() testSuite.addTests(testSuiteFiltered) # run tests TextTestRunner(verbosity=verbosity).run(testSuite)
def main(): __DIR__ = os.path.dirname(os.path.abspath(__file__)) parser = argparse.ArgumentParser(description='Unit test runner') parser.add_argument('--verbose', dest='verbose', action='store_true', default=False, help=' '.join(['Verbosity mode'])) args = parser.parse_args() try: conf = Config(args.__getattribute__('verbose')) except Exception as e: print(f'ERROR: {e}') sys.exit(1) # target: path to the directory used to store the generated XML files. # terminal_path: path to the file used to store the standard output of the # test execution. top_directory = os.path.join(__DIR__, 'tests', 'unit', 'tests') target = os.path.join(__DIR__, 'tests', 'unit', 'result') terminal_path = os.path.join(gettempdir(), 'terminal') if conf.verbose: print(f'XML files will be generated under the directory "{target}".') print(f'Path to the terminal file: "{terminal_path}".') with open(terminal_path, 'w') as terminal: test_suite: TestSuite = defaultTestLoader.discover(start_dir=top_directory, top_level_dir=top_directory, pattern='*_test.py') if conf.verbose: print(f'Number of unit tests: {test_suite.countTestCases()}') result = xmlrunner.XMLTestRunner(output=target, verbosity=1, stream=terminal).run(test_suite) # failure: a test that failed. # error: a Python related error. if len(result.failures) > 0 or len(result.errors) > 0: if conf.verbose: print(f'FAILURE (see file "{terminal_path}")') sys.exit(1) else: if conf.verbose: print('SUCCESS') sys.exit(0)
def main() -> int: args = _parse_args() suite = defaultTestLoader.discover( str(_TESTS), top_level_dir=str(_TOP_LV.parent), pattern=args.pattern ) runner = TextTestRunner( verbosity=args.verbosity, failfast=args.fail, buffer=args.buffer, ) installHandler() r = runner.run(suite) return not r.wasSuccessful()
def run(run_path): read_data(run_path) path = os.getcwd() report_path = path + "/../report" if not os.path.exists(report_path): os.mkdir(report_path) cases = defaultTestLoader.discover(path, pattern="testcase.py") time_str = time.strftime("%Y%m%d_%H%M%S", time.localtime()) # 生成一个年月日时分秒的时间戳 report_path = path + "/../report/自动化测试报告" + time_str + ".html" f = open(report_path, "wb") h = HTMLTestRunner(f, verbosity=2, title="接口自动化") h.run(cases) f.close()
def run_test(**kwargs): """ Run all tests included in "tests" module. Resembles Django's "manage.py test" command. Args: kwargs: Keyword arguments containing backend runtime configurations. """ global db # Set-up in-memory application setup_app(db_uri="sqlite://") db.create_all() # Run tests tests = defaultTestLoader.discover("app/tests") TextTestRunner().run(tests)
def main() -> int: args = _parse_args() suite = defaultTestLoader.discover(normcase(_TESTS), top_level_dir=normcase(_ROOT), pattern="*.py") names = {*_names(args.paths)} tests = (test for test in _tests(suite) if not names or test.__module__ in names) runner = TextTestRunner( verbosity=args.verbosity, failfast=args.fail, buffer=args.buffer, ) installHandler() r = runner.run(TestSuite(tests)) return not r.wasSuccessful()
def test(): """Collect all unit and doct tests and run the test suite.""" suite = defaultTestLoader.discover(TEST_DIR, 'test_*.py', top_level_dir=HERE) doctest_kwargs = dict(optionflags=IGNORE_EXCEPTION_DETAIL) doctest_files = [ os.path.join(DOCS_DIR, 'exceptions.md'), os.path.join(DOCS_DIR, 'index.md'), os.path.join(DOCS_DIR, 'sublemon-objects.md'), os.path.join(DOCS_DIR, 'subprocess-objects.md'), os.path.join(DOCS_DIR, 'utilities.md'), ] for f in doctest_files: doc_tests = DocFileSuite(f, module_relative=False, **doctest_kwargs) suite.addTests(doc_tests) runner = TextTestRunner() result = runner.run(suite) return result.wasSuccessful()
def main(): # parse command-line arguments using docopt command_line_arguments = docopt(__doc__) # get the the regex parameter, if any regex = command_line_arguments["<REGEX>"] if regex: search_pattern = "*" + regex + "*Tester.py" hide_output = False else: search_pattern = "*Tester.py" hide_output = True # add tests to test suite suite = defaultTestLoader.discover( start_dir='testing/tests', pattern=search_pattern, top_level_dir='.') # run test suite if print_in_color: ColourTextTestRunner(verbosity=2, buffer=hide_output).run(suite) else: TextTestRunner(verbosity=2, buffer=hide_output).run(suite)
def build_suite(self, test_labels, extra_tests=None, **kwargs): suite = None discovery_root = settings.TEST_DISCOVERY_ROOT if test_labels: suite = defaultTestLoader.loadTestsFromNames(test_labels) # if single named module has no tests, do discovery within it if not suite.countTestCases() and len(test_labels) == 1: suite = None discovery_root = import_module(test_labels[0]).__path__[0] if suite is None: suite = defaultTestLoader.discover( discovery_root, top_level_dir=settings.BASE_PATH, ) if extra_tests: for test in extra_tests: suite.addTest(test) from django.test.simple import reorder_suite # Django 1.5 and lower return reorder_suite(suite, (TestCase,))
def runTests(path): tests = defaultTestLoader.discover(path) TextTestRunner(verbosity=1).run(tests)
def load_tests(): this_dir = dirname(__file__) return defaultTestLoader.discover( this_dir, top_level_dir=this_dir + '/../..')
#!/usr/bin/python from unittest import defaultTestLoader as loader, TextTestRunner suite = loader.discover(".", "test_*.py") TextTestRunner().run(suite)
def load_all_tests(): return test_loader.discover('tests', pattern='*_tests.py', top_level_dir='.')
#! /usr/bin/python # -*- coding: utf-8 -*- """Discover all tests (except the ones inside test_fa.py) and run them.""" from unittest import defaultTestLoader from unittest.runner import TextTestRunner import config if __name__ == '__main__': config.LANG = 'en' tests = defaultTestLoader.discover('.', '*_test.py') runner = TextTestRunner() runner.run(tests)
""" Test runner which uses unittest ``discover`` method to find all tests within ``cauliflower.testsuite`` and run them. """ import sys import argparse # TODO: try to import unittest2 for python2.4-2.6 backward compatibility from unittest import TextTestRunner, defaultTestLoader TESTSUITE_DIR = 'testsuite' if __name__ == '__main__': parser = argparse.ArgumentParser(description="Yes! It runs the test in testsuite") parser.add_argument('--test', help="which test to run (dotted test path)") args = parser.parse_args() test = args.test # needs to discover before accessing specific tests test_suite = defaultTestLoader.discover(TESTSUITE_DIR) if test is not None: path = '.'.join((TESTSUITE_DIR, test)) test_suite = defaultTestLoader.loadTestsFromName(path) TextTestRunner(verbosity=1).run(test_suite)
import os from unittest import defaultTestLoader here = os.path.basename(__file__) suite = defaultTestLoader.discover('%s/..' % here)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Test runner """ from unittest import (defaultTestLoader, TestSuite, TextTestRunner) from coverage import coverage if __name__ == '__main__': cov = coverage() cov.exclude('test') cov.exclude('tests/') cov.exclude('mock/*') cov.start() test_suite = TestSuite() for _suite in defaultTestLoader.discover('tests', pattern='test_*.py'): for test in _suite: test_suite.addTests(test) TextTestRunner().run(test_suite) cov.stop() cov.save() cov.report()
def suite(): currentDir= os.path.dirname(__file__) topDir= os.path.dirname(currentDir) return defaultTestLoader.discover( start_dir=currentDir, pattern="*.py", top_level_dir=topDir )
#!/usr/bin/env python from unittest import defaultTestLoader, runner if __name__ == '__main__': test = defaultTestLoader.discover('.', 'test_*.py', None) runner.TextTestRunner().run(test)
if __name__ == '__main__': import os from unittest import defaultTestLoader, main dir = os.path.dirname(os.path.abspath(__file__)) defaultTestLoader.discover(dir) main('tests')
__author__ = 'sachinpatney' from unittest import defaultTestLoader from unittest import TextTestRunner suite = defaultTestLoader.discover('.') TextTestRunner().run(suite)
def run(): path = os.path.dirname(__file__) return defaultTestLoader.discover(path)
#!/usr/bin/env python """ TODO: this documentation! """ from unittest import defaultTestLoader, TextTestRunner import sys suite = defaultTestLoader.discover(start_dir=".") result = TextTestRunner(verbosity=2).run(suite) sys.exit(0 if result.wasSuccessful() else 1)
sys.exit(2) testargs.append(arg) # All global variables should be set before any test classes are loaded. # That way, verbose printing can be done at the class definition level. wttest.WiredTigerTestCase.globalSetup(preserve, timestamp, gdbSub, verbose, dirarg, longtest) # Without any tests listed as arguments, do discovery if len(testargs) == 0: if scenario != "": sys.stderr.write("run.py: specifying a scenario requires a test name\n") usage() sys.exit(2) from discover import defaultTestLoader as loader suites = loader.discover(suitedir) suites = sorted(suites, key=lambda c: str(list(c)[0])) if configfile != None: suites = configApply(suites, configfile, configwrite) tests.addTests(restrictScenario(generate_scenarios(suites), "")) else: for arg in testargs: testsFromArg(tests, loader, arg, scenario) if debug: import pdb pdb.set_trace() result = wttest.runsuite(tests, parallel) sys.exit(0 if result.wasSuccessful() else 1)
import time, sys sys.path.append('./interface') sys.path.append('./db_fixture') from HTMLTestRunner import HTMLTestRunner from unittest import defaultTestLoader from db_fixture import test_data # 指定测试用例为当前文件夹下的 interface 目录 test_dir = './interface' testsuit = defaultTestLoader.discover(test_dir, pattern='*_test.py') if __name__ == "__main__": test_data.init_data() # 初始化接口测试数据 now = time.strftime("%Y-%m-%d %H_%M_%S") filename = './report/' + now + '_result.html' fp = open(filename, 'wb') runner = HTMLTestRunner( stream=fp, title='发布会签到系统接口自动化测试', description='运行环境:MySQL(PyMySQL), Requests, unittest ') runner.run(testsuit) fp.close()
import sys from unittest import defaultTestLoader as test_loader from unittest import TextTestRunner print('Testing it') if (len(sys.argv) > 1): print(' with these args: ') for arg in sys.argv[1:]: print(' %s' % arg) test_suite = test_loader.discover('tst/', pattern='*tests.py') test_runner = TextTestRunner(verbosity=2) test_results = test_runner.run(test_suite)