2015-04-28 63 views
0

以下功能:nosetests通过临时字符串混淆反对

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标志设置运行nosetests。

回答

1

通常你会使用这样的:

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

别急,鼻子有shorthand这样的:from nose.tools import eq_

所以对于你的情况,你将有:

eq_(str(very_obscure_obj["text"]), "Another button")