【问题标题】:Pytest can't generate XML output when in unicodePytest 在 unicode 中无法生成 XML 输出
【发布时间】:2013-10-11 09:01:57
【问题描述】:
  1. 转到项目源
  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 在此文件和 _xmlgen.py 文件的其他行上继续失败。

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

【问题讨论】:

  • 找到了解决方法:bitbucket.org/apkawa/pytest/commits/… 但现在它在 py 包中失败:文件“C:\Python27\lib\site-packages\py_xmlgen.py”,第 133 行,在 __object self.write (escape(unicode(obj))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 1305: ordinal not in range(128)
  • 我向 oytest 开发者提交了一个问题,并已修复:bitbucket.org/hpk42/pytest/issue/368/…
  • 如果您已经回答了自己的问题,也许您可​​以写一个答案并接受它?这将使问题显示为“已回答”。

标签: python unicode utf-8 pep8 pytest


【解决方案1】:

我为 pytest 开发人员提交了一个问题,并已修复 https://bitbucket.org/hpk42/pytest/issue/368/unicode-error-when-launching-pytest

【讨论】:

    猜你喜欢
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多