方法返回值的 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

当然我可以将结果(TrueFalsefilecmp.cmp())分配给变量和assert这个变量,但为什么assert适用于第一种方法而不是第二种方法?也许有办法从 filecmp.cmp()assert?

一切似乎都是对的。如果未满足 assert,这看起来像常规 py.test 输出。

path1path2真的相等吗?尝试

assert filecmp.cmp(path1, path1)

查看 assert 语句本身是否有效。