美文网首页
【笔记】appium失败重跑

【笔记】appium失败重跑

作者: pandak | 来源:发表于2018-05-22 15:42 被阅读0次

    python appium失败重跑:

    class Suit(unittest.TestSuite):
        def run(self, result, debug=False):
            failcount = 1  # 失败总运行次数
            class_num = 1
            topLevel = False
            if getattr(result, '_testRunEntered', False) is False:
                result._testRunEntered = topLevel = True
    
            for test in self:
                case_num = 1
                if result.shouldStop:
                    break
    
                success_flag = True
                while success_flag:
                    if _isnotsuite(test):
                        self._tearDownPreviousClass(test, result)
                        self._handleModuleFixture(test, result)
                        self._handleClassSetUp(test, result)
                        result._previousTestClass = test.__class__
                        if (getattr(test.__class__, '_classSetupFailed', False) or
                                getattr(result, '_moduleSetUpFailed', False)):
                            if class_num > failcount:
                                success_flag = False
                            else:
                                time.sleep(5)
                                result._previousTestClass = None
                                print('类%s第%s次重新初始化执行' % (test.__class__, class_num))
                                class_num += 1
                            continue
    
                    if not debug:
                        test(result)
                    else:
                        test.debug()
                    print(result.result)
                    if result.result[-1][0] == 1 or result.result[-1][0] == 2:  # 结果为fail和err用例判断
                        if case_num > failcount:
                                success_flag = False
                        else:
                                print('用例%s第%s次重新执行' % (test, case_num))
                                case_num += 1
                    else:
                            success_flag = False
    
            if topLevel:
                self._tearDownPreviousClass(None, result)
                self._handleModuleTearDown(result)
                result._testRunEntered = False
            return result
    
    
    class _ErrorHolder(object):
        """
        Placeholder for a TestCase inside a result. As far as a TestResult
        is concerned, this looks exactly like a unit test. Used to insert
        arbitrary errors into a test suite run.
        """
        # Inspired by the ErrorHolder from Twisted:
        # http://twistedmatrix.com/trac/browser/trunk/twisted/trial/runner.py
    
        # attribute used by TestResult._exc_info_to_string
        failureException = None
    
        def __init__(self, description):
            self.description = description
    
        def id(self):
            return self.description
    
        def shortDescription(self):
            return None
    
        def __repr__(self):
            return "<ErrorHolder description=%r>" % (self.description,)
    
        def __str__(self):
            return self.id()
    
        def run(self, result):
            # could call result.addError(...) - but this test-like object
            # shouldn't be run anyway
            pass
    
        def __call__(self, result):
            return self.run(result)
    
        def countTestCases(self):
            return 0
    
    
    def _isnotsuite(test):
        "A crude way to tell apart testcases and suites with duck-typing"
        try:
            iter(test)
        except TypeError:
            return True
        return False
    
    
    class _DebugResult(object):
        "Used by the TestSuite to hold previous class when running in debug."
        _previousTestClass = None
        _moduleSetUpFailed = False
        shouldStop = False
    

    相关文章

      网友评论

          本文标题:【笔记】appium失败重跑

          本文链接:https://www.haomeiwen.com/subject/cnahjftx.html