本文整理汇总了Python中HTMLTestRunner.HTMLTestRunner.run方法的典型用法代码示例。如果您正苦于以下问题:Python HTMLTestRunner.run方法的具体用法?Python HTMLTestRunner.run怎么用?Python HTMLTestRunner.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTMLTestRunner.HTMLTestRunner
的用法示例。
在下文中一共展示了HTMLTestRunner.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_and_report
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
def run_and_report(suite=all_tests, verbosity=2, report_filename='report.html',
title='Sage Notebook Tests',
description='Selenium test results',
open_viewer=True, **kwargs):
"""
Runs a test suite and generates a HTML report with the outcome
(pass, fail, or error) and output, including any tracebacks, for
each test, plus overall statistics.
For the SageNB test suite, this assumes a Selenium server or Grid
hub is running with the options given in
:mod:`sagenb.testing.notebook_test_case` or set by
:func:`setup_tests`.
INPUT:
- ``suite`` - a TestSuite instance (default: all_tests); the test
suite to run
- ``verbosity`` - an integer (default: 2); how verbosely to report
instantaneous test results
- ``report_filename`` - a string (default: 'report.html'); the
report's filename
- ``title`` - a string (default: 'Sage Notebook Tests'); the
report's title
- ``description`` - a string (default: 'Selenium test results'); a
description included near the beginning of the report
- ``open_viewer`` - a boolean (default: True); whether to open
the report in a web browser
- ``kwargs`` - a dictionary; extra keyword arguments passed to the
test runner's constructor
EXAMPLES::
sage: import sagenb.testing.run_tests as rt # not tested
sage: rt.run_and_report() # not tested
sage: rt.run_and_report(report_filename='test1.html') # not tested
sage: rt.run_and_report(rt.test_accounts.suite) # not tested
"""
from HTMLTestRunner import HTMLTestRunner
report_fd = open(report_filename, 'w')
runner = HTMLTestRunner(verbosity = verbosity, stream = report_fd,
title = title, description = description,
**kwargs)
runner.run(suite)
if open_viewer:
import os, subprocess
subprocess.Popen(browser() + ' ' + os.path.abspath(report_filename),
shell=True)
示例2: run
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
def run(self):
runner = HTMLTestRunner(
stream=fp,
title=self.base_url+u'首页非200测试',
description=u'用例执行情况:'
)
test_all.BASE_URL = self.base_url
suite.addTest(test_all("test_all_href"))
suite.addTest(test_all("test_all_css"))
suite.addTest(test_all("test_all_img"))
suite.addTest(test_all("test_all_js"))
runner.run(suite)
示例3: start
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
def start(self):
# Set UP of Automation
selenium_wrapper.wrapper().StartSelenium()
selenium_wrapper().wrapper().OpenAppplication()
suite = unittest.defaultTestLoader.loadTestsFromTestCase(test_AddComp)
suite.addTests(unittest.defaultTestLoader.loadTestsFromTestCase(test_EditComp))
suite.addTests(unittest.defaultTestLoader.loadTestsFromTestCase(test_ViewReport))
report_name = self.get_report_name()
print report_name
f=open(str(report_name),"wb+")
runner = HTMLTestRunner(
stream=f,
title='CMA Report',
description='This demonstrates the execution result'
)
result = runner.run(suite)
# Tear Down of Automation
selenium_wrapper.wrapper().StopSelenium()
if not result.wasSuccessful():
sys.exit(1)
示例4: run
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
def run(self, testsuite):
"""Run the testsuite, saving report to fname."""
self.fname = join(abspath('.'), 'testResults.html')
with file(self.fname, 'wb') as fp:
self.stream = fp
self.title = 'Unit Tests'
self.description = 'Summary of Test Run.'
results = Runner.run(self, testsuite)
self.print_summary(results)
return results
示例5: print
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
print('开始了')
self.driver=webdriver.Firefox()
self.driver.implicitly_wait(20)
def test_po_login(self):
'''测试正确的用户名和密码登录'''
base_url=dom_xml('url')
data=open_csv('po_data.csv',1)
self.driver.get(base_url)
#self.driver.get(self.base_url)
self.driver.refresh()
wait_by_linkText(self.driver,'登录')
self.driver.find_element_by_link_text('登录').click()
time.sleep(2)
common_login(self.driver,data['username'],data['password'])
time.sleep(5)
name=self.driver.find_element_by_xpath(".//div[@class='HeaderTopRight']/span").text
if name.find('2473518012'):
print('登录成功')
def tearDown(self):
self.driver.close()
self.driver.quit()
print('结束了')
if __name__=="__main__":
testsuite=unittest.TestSuite()
testsuite.addTest(Login_PO("test_po_login"))
fp=open('./loginresult.html','wb')
runner=HTMLTestRunner(stream=fp,title='PO搜索测试报告',description='用例执行情况')
runner.run(testsuite)
fp.close()
示例6: TestMathFunc
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
tests = [TestMathFunc("test_add"), TestMathFunc("test_minus"), TestMathFunc("test_divide")] # 添加测试用例列表
suite.addTests(tests) # 将测试用例列表添加到测试组中
suite.addTest(TestMathFunc("test_multi")) # 直接用addTest方法添加单个TestCase
# 用addTests + TestLoader。不过用TestLoader的方法是无法对case进行排序的
# loadTestsFromName(),传入'模块名.TestCase名'
suite.addTests(unittest.TestLoader().loadTestsFromName('test_mathfunc.TestMathFunc'))
suite.addTests(unittest.TestLoader().loadTestsFromNames(['test_mathfunc.TestMathFunc'])) # loadTestsFromNames(),类似,传入列表
# loadTestsFromTestCase(),传入TestCase
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestMathFunc))
# suite中也可以套suite
# 将测试结果输出到测试报告中
# with open('UnittestTextReport.txt', 'a') as f:
# runner = unittest.TextTestRunner(stream=f, verbosity=2)
# runner.run(suite)
# 将测试结果输出到测试报告html中
with open('HTMLReport.html', 'w') as f:
runner = HTMLTestRunner(stream=f,
title='MathFunc Test Report',
description='generated by HTMLTestRunner.',
verbosity=2
)
runner.run(suite)
# 直接将结果输出到控制台
# runner = unittest.TextTestRunner(verbosity=2)
# runner.run(suite)
示例7: Creatsuite
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
return testunit
test_case = Creatsuite()
#获取系统当前时间
now = time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime(time.time()))
day = time.strftime('%Y-%m-%d', time.localtime(time.time()))
#定义个报告存放路径,支持相对路径
tdresult = result + day
if os.path.exists(tdresult):
filename = tdresult + "/" + now + "_result.html"
fp = open(filename, 'wb')
#定义测试报告
runner = HTMLTestRunner(stream=fp, title='Appium测试报告', description='用例详情:')
#运行测试用例
runner.run(test_case)
fp.close() #关闭报告文件
else:
os.mkdir(tdresult)
filename = tdresult + "/" + now + "_result.html"
fp = open(filename, 'wb')
#定义测试报告
runner = HTMLTestRunner(stream=fp, title='Appium测试报告', description='用例详情:')
#运行测试用例
runner.run(test_case)
fp.close() #关闭报告文件
示例8: reload
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
# coding:utf-8
import unittest
import time
from HTMLTestRunner import HTMLTestRunner
import sys
reload(sys)
sys.setdefaultencoding('utf8')
test_dir = './'
discover = unittest.defaultTestLoader.discover(test_dir, pattern='test*.py')
if __name__ == '__main__':
now = time.strftime("%Y-%m-%d%H%H%S")
filename = 'G:\\05_pypro\\rest_interface\\report\\' + now + '_restult.html'
fp = open(filename, 'wb')
runner = HTMLTestRunner(stream=fp, title='测试报告', description='用例执行情况:')
runner.run(discover)
fp.close()
示例9: teardown_method
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
def teardown_method(self, method):
test_method_name = self._testMethodName
with allure.step('保存截图'):
self.driver.save_screenshot('../TestResult/ScreenShot/%s.png' % test_method_name)
f = open('../TestResult/ScreenShot/%s.png' % test_method_name, 'rb').read()
allure.attach('自动化截图', f, allure.attach_type.PNG)
with allure.step('---End---'):
self.driver.quit()
if __name__ == '__main__':
suit = unittest.TestSuite()
case_list = [
TestCase('test_order_1'),
TestCase('test_order_2'),
TestCase('test_order_3'),
TestCase('test_order_4'),
TestCase('test_order_5'),
TestCase('test_order_6'),
TestCase('test_order_7'),
TestCase('test_order_8'),
TestCase('test_order_9'),
]
suit.addTests(case_list)
# now = time.strftime("%Y_%m_%d %H_%M_%S")
file = open('../TestResult/order.html', 'wb')
runner = HTMLTestRunner(stream=file, title='WWW下单——测试报告', description='测试情况')
runner.run(suit)
file.close()
示例10: tearDown
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
dr.find_element_by_id("su").click()
def tearDown(self):
self.dr.close()
if __name__ == '__main__':
testunit = unittest.TestSuite()
testunit.addTest(Baidu("test_baidu_search"))
#定义报告存放路径
fp = open('./result.html', 'wb')
#定义测试报告
runner = HTMLTestRunner(stream=fp,
title='百度搜索测试报告',
description='用例执行情况: ')
runner.run(testunit) #运行测试用例
fp.close()
# 执行方式:alt+shfit+F10
"""
发现了问题所在,是软件使用问题运行脚本,楼主一定是用了快捷键CTRL+SHIFT+F10
切记,要用ALT+SHIFT+F10,然后去选择你的脚本的文件名字,去执行。就一切正常了!
在遇到单元测试框架的时候,测试用例本身和下面的执行过程,是分开执行的。
就是说if __name__=="__main__"下面的执行过程是不被执行的。
只是执行了面用例的脚本部分。
"""
示例11: creat_suite
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
import unittest
import time
from HTMLTestRunner import HTMLTestRunner
def creat_suite():
testunit=unittest.TestSuite()
#定义测试文件查找的目录
test_dir=r"D:\mygit\work_one\v_two\app_center"
#定义discover方法的参数
discover=unittest.defaultTestLoader.discover(test_dir,
pattern='test*.py',
top_level_dir=None
)
for test_case in discover:
print test_case
testunit.addTest(test_case)
return testunit
test_time=time.strftime("%Y-%m-%d %H_%M_%S")
# 家里的存放地址
# save_path=os.path.abspath(r"E:\mypython\pengpeng\pp_test_report\testreport")
# 公司的存放地址
#save_path=os.path.abspath(r'D:\mygit\work_one\v_two\pp_test_report\datebase_testreport')
filename='D:\\mygit\\work_one\\v_two\\pp_test_report\\datebase_testreport\\'+test_time+'result.html'
fp=file(filename,'wb')
runner=HTMLTestRunner(stream=fp,
title='数据中心测试报告',
description='设置类子项目测试报告'
)
if __name__=="__main__":
alltestnames=creat_suite()
runner.run(alltestnames)
fp.close()
示例12: test_login01
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
class test_login01(unittest.TestCase):
"""测试说明1"""
def setUp(self):
print ('test start')
def test_login_suess(self):
"""测试说明2"""
www=BaseFun.Base()
"继承了BaseFun01.py下,base类里的各种方法,传入参数直接用"
www.open_browser_with_firefox(r'http://awsbj-openmanagement.xingyunzhi.cn/developer-user/login')#打开网址
www.login('wxg','wxg')#用户名和密码传参数
el=www.by_xpath(".//*[@id='content']/div/div/div/div[2]/div[2]/div/a").text#提取要断言的文字
self.assertEqual('搜索',el)#断言
time.sleep(2)
www.close_browser()
def tearDown(self):
print ('test end')
if __name__=="__main__":
testunit=unittest.TestSuite()
testunit.addTest(test_login01("test_login_suess"))
test_time=time.strftime("%Y_%m_%d_%H_%M_%S")
#save_path=os.path.abspath(r"E:\mypython\pengpeng\pp_test_report\testreport")#家里的存放地址
save_path=os.path.abspath(r"D:\mygit\work_one\pp_test_report\testreport")#公司的存放地址
filename=save_path+test_time+'.html'
print filename
htmlreprot=open(filename,'wb')
runner=HTMLTestRunner(stream=htmlreprot,
title='这是标题',
description='这是测试报告详细内容'
)
runner.run(testunit)
htmlreprot.close()
示例13: test_it_is_false
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
#self.assertTrue(1 != 0)
def test_it_is_false(self):
self.assertFalse(1 == 0)
def test_single_quote_strings(self):
self.assertTrue('aaa' == "aaa")
def test_strip_strings(self):
self.assertTrue(" aaa ".strip() == "aaa")
self.assertTrue(" aaa".lstrip() == "aaa")
self.assertTrue("aaa ".rstrip() == "aaa")
def fun_suite():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
suite.addTests(loader.loadTestsFromTestCase(TestMountain))
return suite
if __name__ == '__main__':
#res = unittest.TextTestRunner(verbosity=2).run(fun_suite())
fp = open('./test_result_%s.html' % time.strftime("%Y-%m-%d %H-%M-%S"), 'wb')
runner = HTMLTestRunner(stream=fp,
title='百度搜索测试报告',
description="测试用例执行情况:")
runner.run(fun_suite())
fp.close()
sys.exit(0)
示例14: reload
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
#!../bin/python
# coding: utf-8
import sys
import unittest
from HTMLTestRunner import HTMLTestRunner
from cases.test_amenity import AmenityTestCase
from cases.test_ubike import UbikeTestCase
# 防止中文錯誤
reload(sys)
sys.setdefaultencoding('utf8')
# 產生 HTML 版本的測試報表
mySuite = unittest.TestSuite()
mySuite.addTest(unittest.makeSuite(AmenityTestCase))
mySuite.addTest(unittest.makeSuite(UbikeTestCase))
runner = HTMLTestRunner(title='OSM.TW 測試報告', description='台灣開放街圖資料完整性測試報告')
runner.run(mySuite)
示例15: all_test
# 需要导入模块: from HTMLTestRunner import HTMLTestRunner [as 别名]
# 或者: from HTMLTestRunner.HTMLTestRunner import run [as 别名]
#前台登录
#suite.addTest(test_login.TestLogin("test_login"))
#发布案件
#suite.addTest(test_publish_case.PublishCase("test_publish_succeed_1"))
#后台审核案件通过
#suite.addTest(test_back_operation.BackOperation("test_back_review"))
#律师申请接案
#suite.addTest(test_lawyer_intake.LawyerIntake("test_lawyer_intake_case"))
#用户指定律师
#suite.addTest(test_user_appoint_lawyer.UserAppoint("test_user_appoint_lawyer"))
#律师完善信息
#suite.addTest(test_perfect_information.PerfectInformat("test_perfect_information"))
#支付代理费
#suite.addTest(test_perfect_information.PerfectInformat("test_lawyer_pay_agent_free"))
#后台审核代理费
suite.addTest(test_back_operation.BackOperation("test_back_agent_review"))
suites.append(suite)
return suites
if __name__ == '__main__':
alltestcase = all_test()
now_time=time.strftime('%Y-%m-%d %H-%M-%S',time.localtime())
filename = './report/'+now_time+'result.html'
fp = open(filename,'wb')
runner = HTMLTestRunner(stream=fp,
title = u'测试报告',
description= u'用例执行情况:')
runner = unittest.TextTestRunner()
runner.run(alltestcase[0])
fp.close()