1. 程式人生 > 其它 >httprunner 3.x報錯OSError: [WinError 6] 控制代碼無效(已解決)

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

重新執行後檢視報告,問題得到解決