def test_001_btn_login(self):
self.startProcess_getDevicesId_StartUIAutoControl()#从此开启多进程,实现多个设备同时运行
def startProcess_getDevicesId_StartUIAutoControl(self): # 先判断一共链接了多少设备
cmdStr = 'adb devices'
pi = subprocess.Popen(cmdStr, shell=True, stdout=subprocess.PIPE)
str = pi.stdout.read()
str1 = str.decode().split('\n')
list1 = str1[1:-2]
newList = []
for i in range(len(list1)):
dd = list1[i].split('\t')
newList.append(dd[0])
self.buildProcess(newList)
def buildProcess(self,newList): # 链接多少设备开启多少进程
phoneDic = {}
phoneList = ['15300067679','15311926129']
for i in range(len(newList)):
phoneDic[newList[i]] = phoneList[i]
p1 = Process(target=self.begin_OperateUI, args=(newList[i],),kwargs=phoneDic)
p1.start()
phoneDic = {}
def begin_OperateUI(self,*devicesIdParam,**phoneDicParam):
global devicesId
devicesId = ''.join(devicesIdParam) # 元组转换为字符串
start_App_Welcome(devicesId)
d = u2.connect_usb(devicesId) # 通过adb devices获取
def test_002_Online_listening(self):
print(devicesId)#提示我未定义,报错
代码如上,问题是这样的,我想在执行完 case1 的时候,在 case2 中直接引用在 case1 中定义好的全局变量 devicesId,因为用例是按照循序执行的,肯定这个时候 devicesId 已经被初始化了,但是,他一直提示有错误,错误具体原因是:NameError: name 'devicesId' is not defined,请大神们帮忙看下是哪里有问题了,谢谢~