sql python assertion error_pyhton 执行完sql,出现Assertion failed

import pymysql

import pytest

conn = pymysql.connect(

user='root',

passwd='123456',

host='localhost',

port=3306,

db='my_test'

)

def test_db():

qs = 'select uid,uname,pwd from test_user'

lst = []

try:

cursor = conn.cursor()

cursor.execute(qs)

# 获取所有的数据

r = cursor.fetchall()

for x in r:

# x 表示列

u = (x[0],x[1],x[2])

lst.append(u)

return lst

finally:

cursor.close()

conn.close()

@pytest.mark.parametrize('uid,uname,pwd',test_db())

def test04(uid,uname,pwd):

print(uid,uname,pwd)

if __name__ == '__main__':

pytest.main(['-vs', 'test_file.py'])

控制台:

============================= test session starts =============================

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self =

query = 'select uid,uname,pwd from test_user', args = None

def execute(self, query, args=None):

"""Execute a query

:param str query: Query to execute.

:param args: parameters used with query. (optional)

:type args: tuple, list or dict

:return: Number of affected rows

:rtype: int

If args is a list or tuple, %s can be used as a placeholder in the query.

If args is a dict, %(name)s can be used as a placeholder in the query.

"""

while self.nextset():

pass

query = self.mogrify(query, args)

> result = self._query(query)

.

def close(self):

"""

Send the quit message and close the socket.

See `Connection.close() `_

in the specification.

:raise Error: If the connection is already closed.

"""

if self._closed:

> raise err.Error("Already closed")

E pymysql.err.Error: Already closed

..\..\..\..\..\Anaconda3\lib\site-packages\pymysql\connections.py:356: Error

========================= 1 failed, 3 passed in 0.30s =========================

Process finished with exit code 1

PASSED [ 50%]1 tom 123

PASSED [ 75%]2 kite 123

PASSED [100%]3 rows 456

Assertion failed

Assertion failed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值