求助:
在写自动化脚本时,在 case 中使用到 ddt 装饰器,然后在单独的 suite.py 界面创建 suite 套件添加测试用例,运行 suite 套件就报错:no such test method in : test_add。然后我把测试套件放到 case 页面里就没问题了。请问是什么问题?
# -*- coding:utf-8 -*-
'''
case:组织机构页面新增机构验证
'''
from selenium import webdriver
from function.page.login import Login
import unittest,time
import ddt
from function.page.xitongguanli.zuzhijg import Zzjg
from function.base.xls import excel
filename="C:\\Users\\11\\PycharmProjects\\new_core\\data\\zixunf.xlsx"
sheetName=u'机构代码'
excel_data=excel(filename)
testdata=excel_data.get_list(sheetName)
@ddt.ddt
class Zzjgcase(unittest.TestCase):
@classmethod
def setUpClass(cls):
# 登录
user = ***
password = ***
cls.driver = webdriver.Firefox()
cls.driver.maximize_window()
cls.driver.implicitly_wait(5)
cls.log = Login(cls.driver, user, password)
cls.log.login()
@classmethod
def tearDownClass(cls):
# cls.driver.close()
pass
def setUp(self):
self.log.page_xtgl(u"系统管理", u"权限管理", u"组织机构")
def tearDown(self):
# self.driver.close()
self.driver.find_element_by_xpath('//span[text()="首页"]').click()
time.sleep(1)
@ddt.data(*testdata)
def test_add(self,data):
zzjg=Zzjg(self.driver)
print (u"场景:%s" % data[u'场景'])
msg = zzjg.add(data[u'路径'], data[u'机构代码'], data[u'机构名称'], data[u'描述'])
try:
self.assertIn(data[u'预期结果'],msg,u"提示信息错误")
except Exception as ee:
print ee
# if __name__ =='__main__':
# suite = unittest.TestLoader().loadTestsFromTestCase(Zzjgcase)
# unittest.TextTestRunner(verbosity=2).run(suite)
def suite():
suiteTest = unittest.TestSuite()
suiteTest.addTest(Zzjgcase("test_add"))
return suiteTest
if __name__ =='__main__':
# unittest.main(defaultTest='suite')
runner=unittest.TextTestRunner()
runner.run(suite())