|-----api
|-----------------init.py
|-----------------api_np.py
|
|-----scripts
------------------init.py
|------------------test01_mp.py
|
|
|-----pytest.ini
api
init.py
##公共变量
#1.请求域名
host="127.0.0.1”
#2.请求信息头
headers={"Content-Type":"application/json"}
api_np.py
import api
import requests
class ApiMp:
#初始化
def __init__(self):
#登录接口url
self.url_login=api.host+"/mp/v1_0/authorizations"
pass
#登录接口
def api_mp_login(self,mobile,code):
#1.定义请求数据
data={"mobile":mobile,"code":code}
#2.调用post方法
return requests.post{url=self.url_login,json=data,headers=api.headers}
def api_mp_article(self,title,content):
#1.定义请求数据
data={"title":title,"content":content}
#2.调用post方法
return requests.post{url=self.url_login,json=data,headers=api.headers}
scripts
init.py
import sys
import os
sys.path.append(os.getcwd())
test01_mp.py
class TestMp:
#初始化
def setup_class(self):
self.mp=ApiMp()
#获取ApiMp对象
#登录接口测试方法
def test01_mp_login(self,mobile="xxxx",code="xxxx"):
#调用登录接口
r=self.mp.api_mp_login(mobile,code)
#打印输出结果
print(r.json())
#发布文章测试接口方法
def test01_mp_article(self):
pytest.ini
[pytest]
addopts=-s --alluredir report
testpaths= ./scripts
python_files=test*.py
python_classes=Test*
python_functions=test*