pytest 中 actual 和 expected 的正确顺序是什么?
What is the correct order for actual and expected in pytest?
这个 question 给出了顺序 assertEqual(expected, actual)
,尽管是针对 unittest 包。
但是Pycharm,用pytest,根据actual==expected
.
的顺序打印出"Expected:..."和"Actual..."
这令人困惑。 pytest 的正确顺序是什么?源码和在线文档就不说了。
(我还注意到 JUnit 和 TestNG 在这一点上存在分歧。)
BDFL 不喜欢 actual/expected terminology and the docs were specifically changed 解决这个问题。
如果您的工具需要按特定顺序进行参数,那么我认为最正确的做法是始终如一地执行对您的工具有效的操作。
JUnit
assertEquals(expected, actual)
Pytest
assert actual == expected
例如:
def test_actual_expected():
expected = 4
actual = 2+1
assert actual == expected
将失败并显示消息
其他人的评论暗示这可能更多的是 PyCharm 显示消息的方式而不是 pytest
本身 - 即。此消息可能不存在于 PyCharm 之外...我不知道。
这个 question 给出了顺序 assertEqual(expected, actual)
,尽管是针对 unittest 包。
但是Pycharm,用pytest,根据actual==expected
.
这令人困惑。 pytest 的正确顺序是什么?源码和在线文档就不说了。
(我还注意到 JUnit 和 TestNG 在这一点上存在分歧。)
BDFL 不喜欢 actual/expected terminology and the docs were specifically changed 解决这个问题。
如果您的工具需要按特定顺序进行参数,那么我认为最正确的做法是始终如一地执行对您的工具有效的操作。
JUnit
assertEquals(expected, actual)
Pytest
assert actual == expected
例如:
def test_actual_expected():
expected = 4
actual = 2+1
assert actual == expected
将失败并显示消息
其他人的评论暗示这可能更多的是 PyCharm 显示消息的方式而不是 pytest
本身 - 即。此消息可能不存在于 PyCharm 之外...我不知道。