PYTHON 接口测试 pytetst终止

PYTHON 接口测试 一个导出表格的接口报错

img

报错信息如下:
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages_pytest\main.py", line 270, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages_pytest\main.py", line 324, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_hooks.py", line 265, in call
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages_pytest\main.py", line 349, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_hooks.py", line 265, in call
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages_pytest\runner.py", line 112, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages_pytest\runner.py", line 131, in runtestprotocol
INTERNALERROR> reports.append(call_and_report(item, "call", log))
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages_pytest\runner.py", line 224, in call_and_report
INTERNALERROR> hook.pytest_runtest_logreport(report=report)
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_hooks.py", line 265, in call
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\pluggy_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\plugins\python-ce\helpers\pycharm\teamcity\pytest_plugin.py", line 310, in pytest_runtest_logreport
INTERNALERROR> self.report_test_failure(test_id, report)
INTERNALERROR> File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\plugins\python-ce\helpers\pycharm\teamcity\pytest_plugin.py", line 225, in report_test_failure
INTERNALERROR> self.report_test_output(report, test_id)
INTERNALERROR> File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\plugins\python-ce\helpers\pycharm\teamcity\pytest_plugin.py", line 206, in report_test_output
INTERNALERROR> dump_test_stdout(self.teamcity, test_id, test_id, data)
INTERNALERROR> File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\plugins\python-ce\helpers\pycharm\teamcity\common.py", line 73, in dump_test_stdout
INTERNALERROR> messages.testStdOut(test_id, chunk, flowId=flow_id)
INTERNALERROR> File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\plugins\python-ce\helpers\pycharm\teamcity\messages.py", line 187, in testStdOut
INTERNALERROR> self.message('testStdOut', name=testName, out=out, flowId=flowId)
INTERNALERROR> File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\plugins\python-ce\helpers\pycharm_jb_runner_tools.py", line 117, in message
INTERNALERROR> _old_service_messages.message(self, messageName, **properties)
INTERNALERROR> File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\plugins\python-ce\helpers\pycharm\teamcity\messages.py", line 101, in message
INTERNALERROR> retry_on_EAGAIN(self.output.write)(self.encode(message))
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3\plugins\python-ce\helpers\pycharm\teamcity\messages.py", line 68, in encode
INTERNALERROR> value = value.encode(self.encoding)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> UnicodeEncodeError: 'gbk' codec can't encode character '\ufffd' in position 1217: illegal multibyte sequence

============================== 1 failed in 1.68s ==============================

以下答案引用自GPT-3大模型,请合理使用:

!

这个报错信息很长,但很明确:接口测试出错,出错的地方是尝试以gbk编码写入文件时遇到了非法字符\ufffd。

解决的办法是:搜索相关的接口文件,找到代码中使用的编码和字符集,然后更改为utf-8,或者使用其他可以编码\ufffd的编码。

也可以尝试将\ufffd字符去除,或者将该字符替换为可正常编码的字符。

如果我的回答解决了您的问题,请采纳我的回答