class TestEdit(unittest.TestCase): unit = unittest.TestCase() do_excel = Doexcel(contants.case_dir, 'hrcycle') cases = do_excel.read_excel() getname = GetName() getevents = GetEvents() setting = Setting() @classmethod def setUpClass(cls): cls.dohttp = Dohttp() @data(*cases) def test_edit(self, case): case.url = replace(case.url) if case.data: case.data = replace(case.data)
class TestApproved(unittest.TestCase): unit = unittest.TestCase() #PermissionError錯誤一定是文件沒關閉 do_excel = Doexcel(contants.case_dir, 'approved') cases = do_excel.read_excel() oaname = OAname() GetApprover() setting = Setting() @classmethod #不定義為類方法 就會每次執行一次用例都調用此方法實例化對象,session就不同了,注意是setUpClass def setUpClass(cls): cls.dohttp = Dohttp() @data(*cases) def test_approved(self,case): case.url = replace(case.url) # 若存在寫在配置文件中的賬號和密碼、項目名,就必須通過replace函數去拿到正則表達式匹配的值 if case.data: case.data = replace(case.data)
def __init__(self): setting = Setting() dbname = setting.config['database']['name'] uri_mongodb = setting.config['database']['uri-mongodb'] self._mongo = MongoClient(uri_mongodb) self._db = self._mongo[dbname]
from common.dbconecction import MongoConnection from common.setting import Setting from common.response.http_status import HttpStatus setting = Setting()