This commit is contained in:
谈林海 2023-04-25 17:58:25 +08:00
parent 1323b200ac
commit ba60b12324
7 changed files with 10 additions and 12 deletions

View File

@ -8,7 +8,7 @@ import pytest
@allure.feature('XXX模块')
@allure.title('XXX接口')
@pytest.mark.imports
@pytest.mark.datafile('test_data/imports/imports.yml')
@pytest.mark.datafile('test_data/imports/test_imports.yml')
def test_imports(core, env, case, inputs, expectation):
# core.requests: 返回请求方法对象
# core.headers: 返回全局请求头

View File

@ -9,7 +9,7 @@ import pytest
@allure.title('登录接口')
@pytest.mark.login
@allure.feature('login')
@pytest.mark.datafile('test_data/login/login.yml')
@pytest.mark.datafile('test_data/login/test_login.yml')
def test_tianqi(core, env, case, inputs, expectation):
res = core.requests.request(env, data=inputs['params'], headers=core.headers).json()
core.cache.add_cache('test_login', res['key'])

View File

@ -7,7 +7,7 @@ import pytest
@allure.feature('天气模块')
@allure.title('天气查询接口')
@pytest.mark.datafile('test_data/tianqi/tianqi.yml')
@pytest.mark.datafile('test_data/tianqi/test_tianqi.yml')
def test_tianqi(core, env, case, inputs, expectation):
# core.requests: 返回请求方法对象
# core.headers: 返回全局请求头

View File

@ -5,8 +5,8 @@ common_inputs:
tests:
- case: 正确账号、密码登录
inputs:
params: {"account": "{{phone_number()}}", "password": "xxxxxxxxxx"}
json:
params: {}
json: {"account": "{{phone_number()}}", "password": "xxxxxxxxxx"}
file:
sql:
assert_key: $..success
@ -16,8 +16,8 @@ tests:
- case: 错误账号、密码登录
inputs:
params: {"account": "18900001000", "password": "xxxxxx"}
json:
params: {}
json: {"account": "18900001000", "password": "xxxxxx"}
file:
sql:
assert_key: $..success

View File

@ -5,7 +5,7 @@ common_inputs:
tests:
- case: 查询上海天气
inputs:
params:
params: { }
json: { "terminal": "PC","apiVersion": "1.0.1","site": { "Siteid": 1015,"siteName": "waibu","qid": "04478","pageType": "null","pageUrl": "https://www.tianqi.com/shanghai/","newsType": "null","keywords": "上海天气,上海天气预报,上海天气预报查询,上海今日天气,上海周末天气,上海一周天气预报,上海天气预报一周,天气预报查询一周,上海天气预报10天,上海天气预报查询15天,上海未来一周的天气预报,上海天气情况,上海40日天气预报,天气预报40天,上海30日天气预报,天气预报30天" },"device": { "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36","geo": { "country": "","city": "" },"dnt": 0,"deviceType": "PC","os": "MACOS","osVersion": "X","height": 1080,"width": 1920 },"user": { "userId": "16805156868205498" },"imp": [ { "slotId": 102298,"pageNum": "{{random_int(1, 5)}}" ,"styleId": [ 1004 ] } ],"requestId": "16805156922345810" }
file:
sql:

View File

@ -67,14 +67,12 @@ class TestCaseAutoCreate(CaseHandler):
data_dict = {k: v for k, v in zip(self.get_data_path[1], self.get_yaml_data)}
for file_path, case_detail in data_dict.items():
file_name = str(file_path).split('/')[-1]
for data in case_detail.get('tests'):
params, jsons, sql = data['inputs'].get('params'), data['inputs'].get('json'), data['inputs'].get('sql')
FileUtils.create_dir(file_path) # 创建目录
case_path = file_path / f'test_{file_name}.py'
feature = str(file_name).split('_')[-1]
case_path = file_path / f'test_{file_path.stem}.py'
FileUtils.write_file(case_path,
content=self.case_content(feature, file_name, params, jsons, sql)) # 写入python文件
content=self.case_content(file_path.stem, f'test_{file_path.stem}', params, jsons, sql)) # 写入python文件
def case_content(self, feature, datafile, params, jsons, sql):
"""生成测试用例内容"""