httprunner 3.x报错OSError: [WinError 6] 句柄无效(已解决)

前言

hrun 命令生成的html报告,虽然用例是通过的,查看详情发现一大堆的报错OSError: [WinError 6] 句柄无效。

问题描述

系统环境:
1.windows 10
2.python3.6.6
3.httprunner 3.1.4
4.pytest 5.4.3
5.pytest-html 2.1.1

问题描述:使用hrun 运行用例,查看详情发现一大堆的报错OSError: [WinError 6] 句柄无效。

>hrun testcases/login_userinfo_test.py --html=./reports/result.html --self-contained-html

生成的html内容

 ------------------------------Captured stderr call------------------------------ 
--- Logging error in Loguru Handler #0 ---
Record was: {'elapsed': datetime.timedelta(0, 1, 859895), 'exception': None, 'extra': {}, 
'file': (name='runner.py', path='e:\\python36\\lib\\site-packages\\httprunner\\runner.py'), 
'function': 'test_start', 'level': (name='INFO', no=20, icon='ℹ️'), 'line': 451, 
'message': 'Start to run testcase: logincase, TestCase ID: e6171c86-3f61-442d-842e-a6f6b105aba6', 
'module': 'runner', 'name': 'httprunner.runner', 'process': (id=10728, name='MainProcess'),
 'thread': (id=15200, name='MainThread'), 'time': datetime(2021, 6, 16, 21, 15, 14, 919264, tzinfo=datetime.timezone(datetime.timedelta(0, 28800), '?D1¨²¡À¨º¡Á?¨º¡À??'))}
Traceback (most recent call last):
  File "e:\python36\lib\site-packages\loguru\_handler.py", line 177, in emit
    self._sink.write(str_record)
  File "e:\python36\lib\site-packages\loguru\_simple_sinks.py", line 26, in write
    self._stream.write(message)
  File "e:\python36\lib\site-packages\colorama\ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "e:\python36\lib\site-packages\colorama\ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "e:\python36\lib\site-packages\colorama\ansitowin32.py", line 187, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "e:\python36\lib\site-packages\colorama\ansitowin32.py", line 196, in write_plain_text
    self.wrapped.flush()
OSError: [WinError 6] 句柄无效。
--- End of logging error ---

解决办法

hrun 执行 pytest 用例还不太完善,改成用 pytest 去执行 py 脚本

>pytest testcases/login_userinfo_test.py --html=./reports/result.html --self-contained-html

重新运行后查看报告,问题得到解决

httprunner 3.x报错OSError: [WinError 6] 句柄无效(已解决)

上一篇:youtube-dl 报错 WinError 10054


下一篇:twisted.internet.error.CannotListenError: Couldn't listen on 127.0.0.1:6073: [WinError 10048] 通