代码:
with open(report_path, mode='wb', encoding='utf-8') as file: runner = HTMLTestRunnerNew.HTMLTestRunner(stream=file, title="123", verbosity=2, description="123") runner.run(suite)
在运行该pytho脚本的时候报错提示:Traceback (most recent call last):
File "F:/pythonProject/Api/run.py", line 9, in <module>
with open(report_path, mode='wb', encoding='utf-8') as file:
ValueError: binary mode doesn't take an encoding argument
之所以报错是文件的做wb操作时不能和encoding一起使用,encoding是个默认参数,可不传值,直接是用默认值即可
修改过后的代码和执行结果如下:
代码:
with open(report_path, mode='wb') as file: runner = HTMLTestRunnerNew.HTMLTestRunner(stream=file, title="123", verbosity=2, description="123") runner.run(suite)
结果: