首页 新闻 会员 周边 捐助

pyhton 执行完sql,出现Assertion failed

0
悬赏园豆:80 [待解决问题]
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 = <pymysql.cursors.Cursor object at 0x000001FC4322A5C8>
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() <https://www.python.org/dev/peps/pep-0249/#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

橙子Cjw的主页 橙子Cjw | 初学一级 | 园豆:109
提问于:2020-11-18 11:22
< >
分享
所有回答(1)
0

生成表时会申明字段类型和约束,传入时要注意顺序和类型以及传入数量

不脱发的小码农 | 园豆:206 (菜鸟二级) | 2020-12-03 01:03

没传参,只是个查询,

支持(0) 反对(0) 橙子Cjw | 园豆:109 (初学一级) | 2020-12-04 08:24

哥 查询select 字段不是参数?字段名要对应

支持(0) 反对(0) 不脱发的小码农 | 园豆:206 (菜鸟二级) | 2020-12-04 13:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册