参考如下:test2中调用 test1中的变量
import unittest
class Doc(unittest.TestCase):
def test1(self):
globals()["token"]=12
def test2(self):
global token
print(token)
if __name__ == '__main__':
unittest.main()
个人应用:
def test_602ScreenMessage(self):
"""获取最初消息的数值"""
num01 = self.driver.find_element_by_xpath('//*[@class="el-badge__content is-fixed"]').text
# num02 = self.driver.find_element_by_xpath('//*[@class="el-badge__content is-fixed"]').text
globals()["a01"] = num01 #准备test调用
print('获取最初消息值:'+num01)
def test_603UnpassMessage(self):
"""获取最初消息的数值"""
num02 = self.driver.find_element_by_xpath('//*[@class="el-badge__content is-fixed"]').text
print('获取最新的消息值:' + num02)
global a01
if int(num02)-int(a01) ==1:
print("消息值增加1,消息数量增加校验通过")
else:
print("消息值增加验证失败")
运行成功记录:
?
|