python - Pytest 断言方法的返回值

标签 python python-3.x pytest

这按预期工作:

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

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

最佳答案

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

path1path2 真的相等吗?尝试一下

assert filecmp.cmp(path1, path1)

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

关于python - Pytest 断言方法的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38991156/

相关文章:

python - Pandas groupby 滚动分位数

c++ - 在 Python3 中将 std::string 转换为 C++ 中的 PyObject

python - pytest 时禁用每个测试 "dots"

python - 使用多个测试用例测试一个功能但只使用一个断言?

python - (ctypes.c_int * len(x))(*x) 是做什么的?

Python Networkx 桥接检测

python控制线性回归中的参数名称

python - 如何编写适用于Python 2和Python 3的代码?

python - Pandas Dataframe - 根据条件获取索引值

xml - 无论如何要指定 .coveragerc 上的报告类型?