0

以下功能:

def test_1():
    assert str(squishtest.object.properties(squishtest.waitForObject(":my_button"))["text"]) == "Another button"

给出:

AssertionError: 
>>  assert str(<module 'squish' from '.../squishtest.so'>.object.properties(<module 'squish' from '.../squishtest.so'>.waitForObject(":my_button"))["text"]) == "Another button"

这没有给我关于按钮实际包含什么文本的信息。

但是,这效果更好:

def test_2():
    s = str(squishtest.object.properties(squishtest.waitForObject(":my_button"))["text"])
    assert s == "Another button"

因为它给出了:

AssertionError: 
    'My button' = str(<module 'squish' from '.../squishtest.so'>.object.properties(<module 'squish' from '.../squishtest.so'>.waitForObject(":startVentButton_Button"))["text"])
>>  assert 'My button' == "Another button"

这里有什么问题?有没有比我在第二个例子中选择的更好的解决方案?

我正在运行带有 -d 标志的鼻子测试。

4

1 回答 1

1

通常你会使用这样的东西:

assert a == b, “%r != %r” % (a, b)

但是等等,nose 有一个这样的简写from nose.tools import eq_

因此,对于您的情况,您将拥有:

eq_(str(very_obscure_obj["text"]), "Another button")
于 2015-04-29T17:53:25.870 回答