先上代码
start.py
if __name__ == '__main__':
suite = unittest.TestSuite()
for cases in case_dir:
cases = unittest.defaultTestLoader.discover(cases, pattern='*Test.py', top_level_dir='medcases')
suite.addTests(cases)
fp = file(filename, 'wb')
#使用 HTMLTestRunner 配置参数,输出报告路径、报告标题、描述
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=report_title, description=report_description)
runner.run(suite)
app_test.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by nil_mmm
import unittest
import android_caps
import traceback
from common import Main
from common import GetScreen
from common import UserLogin
#from flaky import flaky
#import pytest
#@flaky
#@pytest.mark.usefixtures("class")
class Case(unittest.TestCase):
def setUp(self):
self.driver = android_caps.my_driver
print '第一个用例检测'
def tearDown(self):
self.driver.quit()
def test_first(self):
try:
UserLogin.jump_session_page()
print '进入搜索界面'
Main.get_resource_id('tv_search').click()
Main.get_resource_id('et_search_action').send_keys('test')
print '搜索test'
Main.get_resource_id('tv_search').click()
Main.get_resource_id('tv_title')
except:
GetScreen.get_screenshot(self.driver,'test')
traceback.print_exc()
self.fail()
google 了网上的资料,试过了用flaky,还有 testerhome 里面的 pytest,但是都没有成功做到失败重跑,要不就是加了对应的注解后没反应,要么就是 appium 服务挂了,请问要怎么用 pytest 结合 unittest 可以做到失败重跑???