为什么cur.execute('从信用卡中选择id,其中kp_order_id =" A15268964292124586"')为空?

时间:2018-06-05 14:38:44

标签: python-3.x python-unittest pymysql

测试代码有效: 来自常见的导入mysqlDB

                 try{
                     JSONObject data = response.getJSONObject("entry");
                     JSONObject content = data.getJSONObject("content");
                     JSONObject mproperties = content.getJSONObject("mproperties");
                     JSONObject status = mProperties.getJSONObject("dStatus")
                     JSONObject charg = mProperties.getJSONObject("dCharg")
                     String statusText = status.getString("TEXT")
                     String chargText = charg.getString("TEXT")
                    }

                    }catch (JSONException e){
                        e.printStackTrace();
                    }

当我在python unittest中使用它时,返回值为null:

mysql = mysqlDB.MySQLCommand(****)
sqls = ['DELETE FROM `credit_queue_record`;', 'DELETE FROM `fund_queue_record`;', 'DELETE FROM `installment_bill`;', 'DELETE FROM `kporder_queue_record`;', 'DELETE FROM `order_info`;', 'DELETE FROM `transaction_record`;']
mysql.executeSql(sqls)

sql = 'select id from credit where kp_order_id = \"A15268964292124586\"'
print(mysql.querySql(sql))

查询sql:从credit中选择id,其中kp_order_id =" A15268964292124586" 无

˚F

失败:test_one2one(主要 .one2oneTest)

追踪(最近一次通话):   在test_one2one中输入文件" one2one.py",第55行     self.assertIsNotNone(id,msg =' id不应该为空') AssertionError:意外地无:id不应该为空

class querySql()是:     def querySql(self,sql):         print(" query sql:" + sql)

class one2oneTest(unittest.TestCase):
    def setUp(self):    

        #
        # empty the tables
        #
        self.mysql = mysqlDB.MySQLCommand(*********)

        sqls = ['DELETE FROM `credit`;', 'DELETE FROM `credit_queue_record`;', 'DELETE FROM `fund_queue_record`;', 'DELETE FROM `installment_bill`;', 'DELETE FROM `kporder_queue_record`;', 'DELETE FROM `order_info`;', 'DELETE FROM `transaction_record`;']
        self.mysql.executeSql(sqls)

    def test_one2one(self):
        sql = 'select id from credit where kp_order_id = \"A15268964292124586\"'
        id = self.mysql.querySql(sql)
        self.assertIsNotNone(id, msg='id 不应该为空')

1 个答案:

答案 0 :(得分:0)

在查询之前添加time.sleep(5)。也许我很愚蠢。