Exemplo n.º 1
0
    def debug_run_one(self, name=None):
        '''本地调试测试用例,给数据驱动的用例使用,只执行一个用例
        
        :param name: 测试数据名称,如果不指定,执行第一个数据的用例
        '''
        from testbase.runner import TestRunner
        from testbase.loader import TestDataLoader
        from testbase.report import EmptyTestReport
        from testbase.testresult import StreamResult
        from testbase import datadrive

        runner = TestRunner(EmptyTestReport(lambda tc: StreamResult()))
        if self.casedata is None:
            testcls = type(self)
            if datadrive.is_datadrive(testcls):  #数据驱动用例
                tests = datadrive.load_datadrive_tests(testcls, name)
                if len(tests) > 1:
                    tests = [random.choice(tests)]
                return runner.run(tests)
            elif settings.DATA_DRIVE:  #项目级的数据驱动
                testdataset = TestDataLoader().load()
                for it in testdataset:
                    if (name is None) or (str(name) == str(it)):
                        return runner.run([testcls(testdataset[it], str(it))])
                else:
                    raise RuntimeError("找不到指定名字的测试数据")
            else:
                raise RuntimeError("非数据驱动用例请使用debug_run接口进行调试执行")
        else:
            runner.run([self])
            return self
Exemplo n.º 2
0
    def debug_run(self):
        '''本地调试测试用例
        '''
        from testbase.runner import TestRunner
        from testbase.loader import TestDataLoader
        from testbase.report import EmptyTestReport, StreamTestReport
        from testbase.testresult import StreamResult
        from testbase import datadrive

        if self.casedata is None:
            testcls = type(self)
            if datadrive.is_datadrive(testcls):  #数据驱动用例
                runner = TestRunner(
                    StreamTestReport(output_testresult=True,
                                     output_summary=True))
                return runner.run(datadrive.load_datadrive_tests(testcls))
            elif settings.DATA_DRIVE:  #项目级的数据驱动
                testdataset = TestDataLoader().load()
                runner = TestRunner(
                    StreamTestReport(output_testresult=True,
                                     output_summary=True))
                return runner.run(
                    [testcls(testdataset[it], str(it)) for it in testdataset])
        runner = TestRunner(EmptyTestReport(lambda tc: StreamResult()))
        return runner.run([self])
Exemplo n.º 3
0
    def debug_run(self):
        '''本地调试测试用例
        '''
        #2012/08/22 pear    期望这里能返回测试用例的执行结果
        #2012/11/01 pear    SDK发布流程商定由自动改为手动方式,不再需要返回值
        from testbase.runner import TestRunner
        from testbase.loader import TestDataLoader
        from testbase.report import EmptyTestReport, StreamTestReport
        from testbase.testresult import StreamResult
        from testbase import datadrive

        if self.casedata is None:
            testcls = type(self)
            if datadrive.is_datadrive(testcls):  #数据驱动用例
                runner = TestRunner(
                    StreamTestReport(output_testresult=True,
                                     output_summary=True))
                return runner.run([
                    testcls(self.__qtaf_datadrive__[it], str(it))
                    for it in self.__qtaf_datadrive__
                ])
            elif settings.DATA_DRIVE:  #项目级的数据驱动
                testdataset = TestDataLoader().load()
                runner = TestRunner(
                    StreamTestReport(output_testresult=True,
                                     output_summary=True))
                return runner.run(
                    [testcls(testdataset[it], str(it)) for it in testdataset])
        runner = TestRunner(EmptyTestReport(lambda tc: StreamResult()))
        return runner.run([self])
Exemplo n.º 4
0
def debug_run_all():
    '''调试执行当前脚本的全部用例
    '''
    from testbase.loader import TestLoader
    from testbase.runner import TestRunner
    from testbase.report import EmptyTestReport
    from testbase.testresult import StreamResult
    tests = TestLoader().load("__main__")
    runner = TestRunner(EmptyTestReport(lambda tc: StreamResult()))
    runner.run(tests)
Exemplo n.º 5
0
    def debug_run(self):
        '''本地调试测试用例
        '''
        from testbase import datadrive
        from testbase.runner import TestRunner
        from testbase.report import StreamTestReport, EmptyTestReport
        from testbase.testresult import StreamResult

        test_cls = type(self)
        if datadrive.is_datadrive(test_cls) or settings.DATA_DRIVE:  # datadrvie
            if self.casedataname is not None:
                tests = datadrive.load_datadrive_tests(test_cls, self.casedataname)
                report = EmptyTestReport(lambda tc: StreamResult())
            else:
                tests = datadrive.load_datadrive_tests(test_cls)
                report = StreamTestReport(output_testresult=True, output_summary=True)
        else:
            tests = [self]
            report = EmptyTestReport(lambda tc: StreamResult())
        runner = TestRunner(report)
        return runner.run(tests)
Exemplo n.º 6
0
    def debug_run_one(self, name=None):
        '''本地调试测试用例,给数据驱动的用例使用,只执行一个用例

        :param name: 测试数据名称,如果不指定,执行第一个数据的用例
        '''
        from testbase import datadrive
        from testbase.runner import TestRunner
        from testbase.report import EmptyTestReport
        from testbase.testresult import StreamResult

        test_cls = type(self)
        if not datadrive.is_datadrive(test_cls) and not settings.DATA_DRIVE:  # non-datadrive
            raise RuntimeError("非数据驱动用例,请使用debug_run进行调试")
        if name:
            tests = datadrive.load_datadrive_tests(test_cls, name)
        else:
            tests = datadrive.load_datadrive_tests(test_cls)
            tests = tests[:1]
        runner = TestRunner(EmptyTestReport(lambda tc: StreamResult()))
        return runner.run(tests)