Pytest在unicode中无法生成XML输出

2024-10-01 04:53:27 发布

您现在位置:Python中文网/ 问答频道 /正文

  1. 转到项目src
  2. 运行py.test --pep8 --junitxml=pep8.log

第一个控制台显示了pytest已经测试过的.py文件,然后显示一条消息:

INTERNALERROR>   File "C:\Python27\lib\site-packages\_pytest\junitxml.py", line 134, in append_failure
INTERNALERROR>     fail.append(str(report.longrepr))
INTERNALERROR> UnicodeEncodeError: 'ascii' codec can't encode characters in position 1430-1434: ordinal not in range(128)

我试图通过将fail.append(str(report.longrepr))转换为fail.append(str(report.longrepr.encode("utf-8")))来解决这个问题,但是pytest在这个文件的其他行继续失败,并且_XML生成.py文件。在

我认为有一个更好的方法来全局解决这个问题,然后编辑它失败的每一行代码。在


Tags: 文件项目inpyreportsrcpytestencode