(self, tests_mapping)
return test_suite
initialize testcase with Runner() and add to test suite.

        Args:
            tests_mapping (dict): project info and testcases list.

        Returns:
            unittest.TestSuite()
initialize testcase with Runner() and add to test suite.
initialize testcase with Runner () and add to test suite .
def _add_tests(self, tests_mapping):
        """ initialize testcase with Runner() and add to test suite.

        Args:
            tests_mapping (dict): project info and testcases list.

        Returns:
            unittest.TestSuite()

        """

        def _add_test(test_runner, test_dict):
            """ add test to testcase.
            """

            def test(self):
                try:
                    test_runner.run_test(test_dict)
                except exceptions.MyBaseFailure as ex:
                    self.fail(str(ex))
                finally:
                    self.meta_datas = test_runner.meta_datas

            if "config" in test_dict:
                # run nested testcase
                test.__doc__ = test_dict["config"].get("name")
            else:
                # run api test
                test.__doc__ = test_dict.get("name")

            return test

        test_suite = unittest.TestSuite()
        functions = tests_mapping.get("project_mapping", {}).get("functions", {})

        for testcase in tests_mapping["testcases"]:
            config = testcase.get("config", {})

            # 合并共有函数和测试用例里的私有函数
            functions = {**functions, **config.get('functions', {})}

            test_runner = runner.Runner(config, functions)

            TestSequense = type('TestSequense', (unittest.TestCase,), {})

            tests = testcase.get("teststeps", [])
            for index, test_dict in enumerate(tests):
                for times_index in range(int(test_dict.get("times", 1))):
                    # suppose one testcase should not have more than 9999 steps,
                    # and one step should not run more than 999 times.
                    test_method_name = 'test_{:04}_{:03}'.format(index, times_index)
                    test_method = _add_test(test_runner, test_dict)
                    setattr(TestSequense, test_method_name, test_method)

            loaded_testcase = self.test_loader.loadTestsFromTestCase(TestSequense)
            setattr(loaded_testcase, "config", config)
            setattr(loaded_testcase, "teststeps", tests)
            setattr(loaded_testcase, "runner", test_runner)
            test_suite.addTest(loaded_testcase)

        return test_suite
def _add_tests ( self , tests_mapping ) : def _add_test ( test_runner , test_dict ) : """ add test to testcase.
            """ def test ( self ) : try : test_runner . run_test ( test_dict ) except exceptions . MyBaseFailure as ex : self . fail ( str ( ex ) ) finally : self . meta_datas = test_runner . meta_datas if "config" in test_dict : # run nested testcase test . __doc__ = test_dict [ "config" ] . get ( "name" ) else : # run api test test . __doc__ = test_dict . get ( "name" ) return test test_suite = unittest . TestSuite ( ) functions = tests_mapping . get ( "project_mapping" , { } ) . get ( "functions" , { } ) for testcase in tests_mapping [ "testcases" ] : config = testcase . get ( "config" , { } ) # 合并共有函数和测试用例里的私有函数 functions = { * * functions , * * config . get ( 'functions' , { } ) } test_runner = runner . Runner ( config , functions ) TestSequense = type ( 'TestSequense' , ( unittest . TestCase , ) , { } ) tests = testcase . get ( "teststeps" , [ ] ) for index , test_dict in enumerate ( tests ) : for times_index in range ( int ( test_dict . get ( "times" , 1 ) ) ) : # suppose one testcase should not have more than 9999 steps, # and one step should not run more than 999 times. test_method_name = 'test_{:04}_{:03}' . format ( index , times_index ) test_method = _add_test ( test_runner , test_dict ) setattr ( TestSequense , test_method_name , test_method ) loaded_testcase = self . test_loader . loadTestsFromTestCase ( TestSequense ) setattr ( loaded_testcase , "config" , config ) setattr ( loaded_testcase , "teststeps" , tests ) setattr ( loaded_testcase , "runner" , test_runner ) test_suite . addTest ( loaded_testcase ) return test_suite