標(biāo)簽:cur python self sql 接口 user conn mysql def 1.comm里放置數(shù)據(jù)操作代碼 2.conftest.py里放置刪除用戶代碼 3.test_register.py里放置測試注冊用戶的代碼(運行注冊接口之前先從數(shù)據(jù)庫刪除注冊的賬號) ----------------------------comm--------------------------------------- import pymysql dbinfo={ "host":"192.16.8.x", "post":3306, "user":"root", "password":"xxxx", "database":"xxx" } class DBopera: def __init__(self,dbinfo=dbinfo): self.conn = pymysql.connect(**dbinfo) self.cur = self.conn.cursor() def dbselect(self,sql): self.cur.execute(sql) result = self.cur.fetchall() print(result) def dbcommit(self,sql): self.cur.execute(sql) self.conn.commit() def dbclose(self): self.cur.close() self.conn.close() ----------------------------------------------------------------------- ------------------------------conftest.py------------------------------ import pytest import pymysql from comm import conn.DBopera @pytest.fixture(params=["username1","username2"] def delete_user(request): user = request.param db = DBopera() db.dbcommit(sql='delete from tablename where username = "%s";'%user) db.close() return user -------------------------test_register.py------------------------------ import requests def test_register(delete_user): url = "http://xxxx/register" body = { "username":delete_user, "password":"123456", "email":"[email protected]" } r = requests.post(url,json=body) print(r.text()) 標(biāo)簽:cur,python,self,sql,接口,user,conn,mysql,def |
|