使用 eq_ 和鼻子测试,有没有办法知道两个字符串的哪一行和哪一行不同?

发布于 2024-12-22 18:01:40 字数 230 浏览 3 评论 0原文

来自其他一些技术,在单元测试中使用了字符串比较断言,这些断言在一行上显示字符串 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2024-12-29 18:01:40

如果您将 unittestnose 结合使用,您可能正在寻找 unittest.TestCase.assertMultilineEqual

If you're using unittest with nose, you are probably looking for unittest.TestCase.assertMultilineEqual.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文