python - `assert 1,2 == (2,3)` 不会在 python3 中引发 AssertionError

标签 python testing assertion

如标题所述

我希望

assert 1,2 == (2,3)

引发 AssertionError 但它没有。

也不是

assert 1,2 == 2

有人知道为什么吗?

最佳答案

assert 语法将检查逗号之前的内容,接下来是在断言为 False 时打印的内容。

试一试:

>>> assert 0,2 == (2,3)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AssertionError: False

您需要执行 assert (1, 2) == (2, 3), "Assertion failure !"

关于python - `assert 1,2 == (2,3)` 不会在 python3 中引发 AssertionError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54828536/

相关文章:

Python 谷歌翻译

python - 将结构体元胞数组从 Python 传递到 MATLAB

iphone - iTunes Connect 重新添加测试用户?

c++ - Luabind 断言失败

ruby - Watir 检查文本是否存在

python - 我想调用 HDFS REST api 来上传文件

python - 如何将 python 脚本的输出传输到 Rscript 中?

testing - 测试目录 - 常见错误或测试用例

testing - calabash-android:是否可以忽略固定(预定义)步骤?

python - tensorflow.python.framework.errors_impl.InvalidArgumentError : Invalid argument: assertion failed: