nosetests混淆临时字符串对象

2024-09-28 05:15:47 发布

您现在位置:Python中文网/ 问答频道 /正文

以下功能:

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标志做鼻测试。你知道吗


Tags: textfromsoobjectmydefanotherbutton
1条回答
网友
1楼 · 发布于 2024-09-28 05:15:47

通常您会使用以下内容:

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

但是等等,鼻子有这样一个shorthandfrom nose.tools import eq_

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

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

相关问题 更多 >

    热门问题