方法返回值的 Pytest 断言
Pytest assert of returned value from method
这是按预期工作的:
def my_method():
return True;
def test_method():
assert my_method()
但这不是:
assert filecmp.cmp(path1, path2)
相反,我得到:
AssertionError: assert <function cmp at 0x1042db840>((((('/Users/vital...my-path
当然我可以将结果(True
或False
从filecmp.cmp()
)分配给变量和assert
这个变量,但为什么assert
适用于第一种方法而不是第二种方法?也许有办法从 filecmp.cmp()
到 assert
?
一切似乎都是对的。如果未满足 assert
,这看起来像常规 py.test 输出。
path1
和path2
真的相等吗?尝试
assert filecmp.cmp(path1, path1)
查看 assert
语句本身是否有效。
这是按预期工作的:
def my_method():
return True;
def test_method():
assert my_method()
但这不是:
assert filecmp.cmp(path1, path2)
相反,我得到:
AssertionError: assert <function cmp at 0x1042db840>((((('/Users/vital...my-path
当然我可以将结果(True
或False
从filecmp.cmp()
)分配给变量和assert
这个变量,但为什么assert
适用于第一种方法而不是第二种方法?也许有办法从 filecmp.cmp()
到 assert
?
一切似乎都是对的。如果未满足 assert
,这看起来像常规 py.test 输出。
path1
和path2
真的相等吗?尝试
assert filecmp.cmp(path1, path1)
查看 assert
语句本身是否有效。