Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pytest_assertrepr_compare only失败_Python_Unit Testing_Testing_Pytest - Fatal编程技术网

Python pytest_assertrepr_compare only失败

Python pytest_assertrepr_compare only失败,python,unit-testing,testing,pytest,Python,Unit Testing,Testing,Pytest,我是pytest的新手,正在研究如何定制断言。这个来自pytest网站的例子失败了,即使我比较Foo(1)==Foo(1)。知道为什么吗 配置: # content of conftest.py from test_foocompare import Foo def pytest_assertrepr_compare(op, left, right): if isinstance(left, Foo) and isinstance(right, Foo) and op == "==":

我是pytest的新手,正在研究如何定制断言。这个来自pytest网站的例子失败了,即使我比较Foo(1)==Foo(1)。知道为什么吗

配置:

# content of conftest.py
from test_foocompare import Foo
def pytest_assertrepr_compare(op, left, right):
    if isinstance(left, Foo) and isinstance(right, Foo) and op == "==":
        return ['Comparing Foo instances:',
                '   vals: %s != %s' % (left.val, right.val)]
测试:

结果:

$ pytest -q test_foocompare.py
F
======= FAILURES ========
_______ test_compare ________

    def test_compare():
        f1 = Foo(1)
        f2 = Foo(1)
>       assert f1 == f2
E       assert Comparing Foo instances:
E            vals: 1 != 1

奇怪,你的考试对我来说通过了。一开始它失败了,但我把
\uuuuueq\uuuu()
方法的缩进搞砸了。检查你没有混淆标签和空格之类的东西


假设这不是您的问题,如果您使用Eclipse或PyCharm,我建议您尝试使用调试器运行它。查看等式语句正在比较的值。如果您使用的是Emacs,您可以尝试安装my以查看发生了什么。

奇怪的是,您的测试对我来说是通过的。一开始它失败了,但我把
\uuuuueq\uuuu()
方法的缩进搞砸了。检查你没有混淆标签和空格之类的东西

假设这不是您的问题,如果您使用Eclipse或PyCharm,我建议您尝试使用调试器运行它。查看等式语句正在比较的值。如果您使用的是Emacs,您可以尝试安装my来查看发生了什么

$ pytest -q test_foocompare.py
F
======= FAILURES ========
_______ test_compare ________

    def test_compare():
        f1 = Foo(1)
        f2 = Foo(1)
>       assert f1 == f2
E       assert Comparing Foo instances:
E            vals: 1 != 1