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 alogin(self, username, passwd, hope): sign = login(username, passwd) return sign @parameterized.expand( [ ['niuhanyang','123456','138'], ['niuhanyang','',False], ['','', False], ['niuhanyang','123',False] ] ) def test_choujiang(self,username,passwd,hope):#只有test开头的用例才会被执行 sign=self.alogin(username,passwd,hope) #获取前一条用例的执行结果,赋值给sign cj_res=choujiang(sign) self.assertEqual(cj_res,True) if __name__=='__main__': suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(My)) fw = open('获取结果.html', 'wb') runner = HTMLTestRunner.HTMLTestRunner(stream=fw, title='获取前一条用例执行结果') runner.run(suite)
执行结果