代码
原代码:
import time
import unittest
import logging
from time import sleep
from BSTestRunner import BSTestRunner
#指定测试用例和测试报告的路径
test_dir=‘./testcase‘
report_dir=‘./report‘
#加载测试用例
discover=unittest.defaultTestLoader.discover(test_dir,pattern="nifeng.py")
#定义报告的文件格式
now=time.strftime("%Y-%m-%d %H_%M_%S")
report_name=report_dir+‘/‘+ now +"test_report.html"
#运行用例并生成测试报告
with open(report_name,"wb")as f:
runner= BSTestRunner(stream=f,title=u"泥蜂登录测试报告",description=u"测试报告")
runner.run(discover)
报错:
D:\python\python.exe D:/pycharm/project/nifeng/run.py
Traceback (most recent call last):
File "D:\pycharm\project\nifeng\run.py", line 16, in <module>
with open(report_name,"wb")as f:
FileNotFoundError: [Errno 2] No such file or directory: ‘./report/2021-06-20 18_06_25test_report.html‘
解决方案:
测试报告路径
report_dir=‘./report‘
改成绝对路径
report_dir=‘D:/pycharm/project/nifeng/reports‘
with open() 报错FileNotFoundError: [Errno 2] No such file or directory