nosetests没有检测到我的测试用例应该失败

时间:2013-12-04 01:09:48

标签: python

我正在尝试运行我的第一个python - nosetests。但是,测试不会发现错误的值,并且总是通过它。

#!/usr/bin/env python

import MySQLdb
import xml.etree.cElementTree as ET

def testCase9p():
    # Open database: qa, and report connection
    db1 = MySQLdb.connect("host1","usr1","passwd1","db1" )
    db2 = MySQLdb.connect("host","usr2","passwd2","db2" )

    # prepare a cursor object using cursor() method
    query1 = db1.cursor()
    query2 = db2.cursor()

    query1.execute("select modified from dcp where jobid =7;")
    query2.execute("Select modified from jusage where jobid =7")

    # Fetch a single row using fetchone() method.
    data1 = query1.fetchone()
    data2 = query2.fetchone()

    if (data1 == data2):
        field1.text = "Pass"
        return True
    else:
        field1.text = "Fail"
        return False
    db1.close()
    db2.close()
result=testCase9p()

然后我跑了" nosetests --with-xunit"但结果是没有检测到它认为失败了。 (我从后端知道他们不应该比较,我在哪里做不正确?

1 个答案:

答案 0 :(得分:0)

nosetests正在寻找一段失败的代码。尝试更改以下代码

if (data1 == data2):
    field1.text = "Pass"
    return True
else:
    field1.text = "Fail"
    return False

assert data1 == data2