pytest 数据驱动mysql数据库
pip install mysqlclient
import MySQLdb
import pytest
conn = MySQLdb.connect( #获取一个conn
    user='root',
    passwd='123456',
    host='localhost',
    port=3306,
    db='test_ddt'
)
def get_data():
    query_sql = 'select id,name,age from person'
    lst = []
    try:
        cursor = conn.cursor() #获取一个游标
        cursor.execute(query_sql) #游标执行sql语句
        r = cursor.fetchall()
        for x in r:
            lst.append(x)
        return lst
    finally:
        cursor.close()
        conn.close()
@pytest.mark.parametrize('id, name, age', get_data()) #多个字段在同一个引号下,用逗号分隔
def test1(id, name, age):
    print(id, name, age)
if __name__ == '__main__':
    pytest.main(['-sv','test_mysql.py'])

 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号