day11_获取前一条用例的结果(用参数化实现)

import unittest,HTMLTestRunner
from nose_parameterized import parameterized
def login(username,passwd):
if username == 'niuhanyang' and passwd == '123456':
return '138'
return False

def choujiang(sign):
if sign == '138':
return True
return False

class My(unittest.TestCase):
def login(self,username,passwd,hope):
sign = login(username,passwd)
self.assertEqual(sign,hope)
return sign

@parameterized.expand( # 放在有test的用例上面
[
['laosun0204','123456','138'],
['lao','121',False],
]
)
def test_choujiang(self,username,passwd,hope):
sign = self.login(username,passwd,hope)
cj_res = choujiang(sign)
self.assertEqual(cj_res,True)

if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(My))
fw = open('login.html','wb')
runner = HTMLTestRunner.HTMLTestRunner(stream = fw)
runner.run(suite)
posted @ 2018-03-19 17:21  laosun0204  阅读(98)  评论(0编辑  收藏  举报