【メモ】appium失敗再走
3522 ワード
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 "" % (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