【问题标题】:Error comparing long string output in Python test在 Python 测试中比较长字符串输出时出错
【发布时间】:2012-10-12 05:24:09
【问题描述】:

我正在测试一个 Python 脚本,该脚本在执行时会抛出一堆字节(作为字符串)。

首先,我得到结果:

myOutput = subprocess.check_output(["python","../src/myScript.py"])

有了这个,我执行脚本并获得输出。

然后我将这个结果与一个很长的预期输出进行比较:

expOutput = "382d006e756c6c2c7465737453657450726f706572747953823c75652c6c75614170702c63617074696f6e2c486f6c61206d756e646f203200"
self.assertEqual(myOutput, expOutput, "Script output is not the expected") 

(这只是一个愚蠢的测试,我正在尝试让事情正常工作)。

问题:我的测试失败。调试我发现值是相等的。

谁能帮助我?

谢谢!

【问题讨论】:

  • assertEqual 中的代码是什么?

标签: python string unit-testing subprocess python-unittest


【解决方案1】:

在被调用脚本的输出末尾可能是一个杂散的 eol。试试这个:

myOutput = myOutput.strip()
self.assertEqual(myOutput, expOutput, "Script output is not the expected")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2016-05-31
    • 2017-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多