Preface
The html report generated by hrun command, although the use case is passed, check the details to find a large number of reported errors OSError: [WinError 6] Handle invalid.
Problem Description
System environment.
1.windows 10
2.python3.6.6
3.httprunner 3.1.4
4.pytest 5.4.3
5.pytest-html 2.1.1
Problem Description: Using hrun to run the use case, checking the details found a bunch of errors reporting OSError: [WinError 6] Invalid handle.
>hrun testcases/login_userinfo_test.py –html=. /reports/result.html –self-contained-html
Generated html content
——————————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] The handle is invalid.
— End of logging error —
Solution:
The hrun execution pytest use case is not perfect, so instead use pytest to execute the py script
>pytest testcases/login_userinfo_test.py –html=. /reports/result.html –self-contained-html
After re-running the report, the problem was solved