Skip to content

Commit

Permalink
优化部分文件细节处理 (#201)
Browse files Browse the repository at this point in the history
* 优化部分文件细节处理

* 修复typing检测

* 细节抛光

* 修复格式化
  • Loading branch information
wu-clan authored Aug 29, 2024
1 parent 2824e6d commit 1adbd73
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 37 deletions.
2 changes: 1 addition & 1 deletion httpfpt/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def pytest_runtest_makereport(item, call):

def pytest_collection_modifyitems(items):
"""
解决数据驱动ids参数为中文时,控制台输出乱码问题
更新收集的测试用例配置
:param items:
:return:
Expand Down
9 changes: 5 additions & 4 deletions httpfpt/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def startup(
def run(
*args,
# auto testcases
testcase_generate: bool = False,
testcase_re_generation: bool = True,
testcase_generate: bool = True,
testcase_re_generation: bool = False,
# init
clean_cache: bool = False,
pydantic_verify: bool = True,
Expand Down Expand Up @@ -212,7 +212,7 @@ def run(
:return:
"""
try:
logo = f"""\n
banner = f"""\n
/$$ /$$ /$$$$$$$$ /$$$$$$$$ /$$$$$$$ /$$$$$$$$ /$$$$$$$ /$$$$$$$$
| $$ | $$|__ $$__/|__ $$__/| $$__ $$| $$_____/| $$__ $$|__ $$__/
| $$ | $$ | $$ | $$ | $$ | $$| $$ | $$ | $$ | $$
Expand All @@ -223,9 +223,10 @@ def run(
|__/ |__/ |__/ |__/ |__/ |__/ |__/ |__/
Starting...
Version: {get_version(cli=False)}
"""
log.info(logo)
log.info(banner)
redis_client.init()
case_data.clean_cache_data(clean_cache)
case_data.case_data_init(pydantic_verify)
Expand Down
12 changes: 4 additions & 8 deletions httpfpt/testcases/test_project/test_api_testcase_template.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import allure
import pytest

from httpfpt.common.send_request import send_request
from httpfpt.utils.request.case_data_parse import get_testcase_data

allure_data, ddt_data, ids = get_testcase_data(filename='api_testcase_template.yaml')
ddt_data, ids = get_testcase_data(filename='api_testcase_template.yaml')


@allure.epic(allure_data['epic'])
@allure.feature(allure_data['feature'])
class TestApiTestcaseTemplate:
"""ApicaseTemplate"""

@allure.story(allure_data['story'])
@pytest.mark.parametrize('data', ddt_data, ids=ids)
def test_api_testcase_template(self, data):
@pytest.mark.parametrize('case_data', ddt_data, ids=ids)
def test_api_testcase_template(self, case_data):
"""api_testcase_template"""
send_request.send_request(data)
send_request.send_request(case_data)
12 changes: 4 additions & 8 deletions httpfpt/testcases/test_project/test_only_skip.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import allure
import pytest

from httpfpt.common.send_request import send_request
from httpfpt.utils.request.case_data_parse import get_testcase_data

allure_data, ddt_data, ids = get_testcase_data(filename='only_skip.yml')
ddt_data, ids = get_testcase_data(filename='only_skip.yml')


@allure.epic(allure_data['epic'])
@allure.feature(allure_data['feature'])
class TestOnlySkip:
"""OnlySkip"""

@allure.story(allure_data['story'])
@pytest.mark.parametrize('data', ddt_data, ids=ids)
def test_only_skip(self, data):
@pytest.mark.parametrize('case_data', ddt_data, ids=ids)
def test_only_skip(self, case_data):
"""only_skip"""
send_request.send_request(data)
send_request.send_request(case_data)
12 changes: 4 additions & 8 deletions httpfpt/testcases/test_project/test_upload_file.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import allure
import pytest

from httpfpt.common.send_request import send_request
from httpfpt.utils.request.case_data_parse import get_testcase_data

allure_data, ddt_data, ids = get_testcase_data(filename='upload_file.json')
ddt_data, ids = get_testcase_data(filename='upload_file.json')


@allure.epic(allure_data['epic'])
@allure.feature(allure_data['feature'])
class TestUploadFile:
"""UploadFile"""

@allure.story(allure_data['story'])
@pytest.mark.parametrize('data', ddt_data, ids=ids)
def test_upload_file(self, data):
@pytest.mark.parametrize('case_data', ddt_data, ids=ids)
def test_upload_file(self, case_data):
"""upload_file"""
send_request.send_request(data)
send_request.send_request(case_data)
4 changes: 2 additions & 2 deletions httpfpt/utils/case_auto_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def auto_generate_testcases(rewrite: bool = False) -> None:
# -*- coding: utf-8 -*-
import pytest
from common.send_request import send_request
from utils.request.case_data_parse import get_testcase_data
from httpfpt.common.send_request import send_request
from httpfpt.utils.request.case_data_parse import get_testcase_data
ddt_data, ids = get_testcase_data(filename='{file_property[0]}')
Expand Down
8 changes: 6 additions & 2 deletions httpfpt/utils/cli/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations

import re

from importlib.resources import read_text
Expand All @@ -9,13 +11,15 @@
from httpfpt.utils.rich_console import console


def get_version(cli: bool = True) -> None:
def get_version(cli: bool = True) -> str | None:
"""获取版本号"""
ver = read_text('httpfpt', '__init__.py')
mob = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", ver, re.MULTILINE)
if mob:
version = mob.group(1)
if cli:
console.print('')
console.print(f'HTTPFPT: [cyan]{mob.group(1)}[/]')
console.print(f'HTTPFPT: [cyan]{version}[/]')
return version
else:
raise cappa.Exit('\n❌ 未查询到版本号', code=1)
6 changes: 2 additions & 4 deletions httpfpt/utils/request/request_data_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,12 @@ def proxies(self) -> dict | None:
raise RequestDataParseError(_error_msg('参数 config:request:proxies 不是有效的 dict 类型'))
keys = list(proxies.keys())
if 'http' not in keys or 'https' not in keys:
raise RequestDataParseError(
_error_msg('测试用例数据解析失败,参数 config:request:proxies 不符合规范')
)
raise RequestDataParseError(_error_msg('参数 config:request:proxies 不符合规范'))
for v in proxies.values():
if v is not None:
if not isinstance(v, str):
raise RequestDataParseError(
_error_msg(f'测试用例数据解析失败,参数 config:request:proxies:{v} 不是有效的 str 类型')
_error_msg(f'参数 config:request:proxies:{v} 不是有效的 str 类型')
)
if self.request_engin == EnginType.requests:
proxies = proxies
Expand Down

0 comments on commit 1adbd73

Please sign in to comment.