pytest 中实际和预期的正确顺序是什么?

问题描述 投票:0回答:2

这个问题给出了顺序

assertEqual(expected, actual)
,尽管是针对unittest包的。

但是 Pycharm 与 pytest 会根据顺序打印出“预期:...”和“实际...”

actual==expected

这很令人困惑。 pytest 的正确顺序是什么?源码和网上文档就不说了。

(我还注意到 JUnit 和 TestNG 在这一点上存在分歧。)

python pytest python-unittest
2个回答
30
投票

JUnit

assertEquals(expected, actual)

Pytest(Pycharm)

评论暗示这可能更多是 PyCharm 显示消息的方式的问题,而不是

pytest
本身的问题 - 即。此消息可能不存在于 PyCharm 之外...

assert actual == expected

例如:

def test_actual_expected():
    expected = 4
    actual = 2+1
    assert actual == expected

失败并显示消息


16
投票

BDFL 不喜欢实际/预期的术语,文档已专门更改来解决这个问题。

如果您的工具期望按特定顺序接收参数,那么我认为最正确的做法是始终如一地执行适合您的工具的操作。

© www.soinside.com 2019 - 2024. All rights reserved.