报错如下:局部变量赋值前被引用
<configparser.ConfigParser object at 0x10ec52350>
Traceback (most recent call last):
File “/Users/python自动化学习笔记/interfaceTest/runAll.py”, line 101, in
AllTest().run()
File “/Users/python自动化学习笔记/interfaceTest/runAll.py”, line 92, in run
fp.close()
UnboundLocalError: local variable ‘fp’ referenced before assignment
源码如下:
def run(self):
try:
suit=self.set_case_suite()
print("try")
print(str(suit))
if suit is not None:
print("if-suite")
fp=open(resultPath,'wb')
runner=HtmlTestRunner.HTMLTestRunner(stream='fp',title='Test Report',description='Test description')
runner.run(suit)
else:
print("have no case to test.")
except Exception as ex:
print(str(ex))
finally:
print("**********test end!**********")
fp.close()
#判断邮件发送的开关:
if on_off=="on":
send_mail.send_email()
else:
print("邮件发送配置开关关闭,请打开邮件配置开关后再次发送邮件")