unittest中忽略某些测试用例的执行
添加装饰器(@unittest.skip(""))
from init import *
import unittest
class baidu(Info):
@unittest.skip("新闻功能已经取消,跳过该测试项")
def test_baidu_news(self):
self.driver.find_element_by_link_text("新闻").click()
def test_baidu_map(self):
self.driver.find_element_by_link_text("地图").click()
if __name__ == "__main__":
unittest.main(verbosity=2)
执行结果如下:
Ran 2 tests in 7.452s OK (skipped=1) Skipped: 新闻功能已经取消,跳过该测试项
如果期望测试用例失败,也可以添加装饰器
import unittest
class Test(unittest.TestCase):
@unittest.expectedFailure
def test_add(self):
self.assertEqual(1, 4)
if __name__ == "__main__":
unittest.main(verbosity=2)