使用 eq_ 和鼻子测试,有没有办法知道两个字符串的哪一行和哪一行不同?
来自其他一些技术,在单元测试中使用了字符串比较断言,这些断言在一行上显示字符串 1(在控制台输出中),在第二行显示字符串 2,并提示您 # 是第一个差异的位置(当有差异时)。
我认为我可以轻松地编写一个助手来完成此任务,但我想在重新发明轮子之前检查是否存在类似的东西。现在我正在使用 eq_ 并且(至少在 PyCharm 中)它对于揭示涉及长字符串和/或多行字符串时的差异没有用。
还有比 eq_ 更有用的东西吗?
Coming from some other technologies, there have been string comparison assertions for use in unit tests that show string 1 on one line (in the console output) and string 2 on the second line, and clue you to what position # is the first difference (when there is a difference).
I think I can write a helper easily enough to accomplish this but thought I'd check if something like this exists before re-inventing a wheel. Right now I'm using eq_ and (at least within PyCharm) it isn't useful in revealing where the difference is when long and/or multi-line strings are involved.
Is there something more useful than eq_ ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将
unittest
与nose
结合使用,您可能正在寻找unittest.TestCase.assertMultilineEqual
。If you're using
unittest
withnose
, you are probably looking forunittest.TestCase.assertMultilineEqual
.