day98 pytest的fixture功能之session
学习日期:20241215
学习目标:pytest基础用法 -- pytest的fixture功能之session
学习笔记:
fixture(scop="session")
- (scop="session") 是多个文件调用一次,.py文件就是module
import pytest
import requests
@pytest.fixture(scope="module",autouse=True)
def func():
print("我是前置步骤")
class TestClassFixture:
def test_getmobile(self):
print("测试get请求")
params = {'key1': 'value1', 'key2': 'value2'}
r=requests.get('https://httpbin.org/get',params=params)
print(r.status_code)
assert r.status_code == 200
res = r.json()
assert res['url'] == 'https://httpbin.org/get?key1=value1&key2=value2'
assert res['origin'] == '163.125.202.248'
assert res['args']['key1'] == 'value1'
assert res['args']['key2'] == 'value2'
def test_postmobile(self):
print("测试post请求")
params = {'key': 'value'}
r = requests.post('https://httpbin.org/post', data=params)
print(r.status_code)
assert r.status_code == 200
print(r.json())
res=r.json()
assert res['args'] == {}
assert res['data'] == ''
assert res['form']['key'] == 'value'
if __name__ == '__main__':
pytest.main()
总结
- (scop="session") 是多个文件调用一次,.py文件就是module