Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新测试启动项配置 #199

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions httpfpt/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import pytest

from httpfpt.utils.cli.version import get_version

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from httpfpt.common.log import log
Expand All @@ -29,7 +31,6 @@

def startup(
*args,
testcase_generate: bool,
log_level: Literal['-q', '-s', '-v', '-vv'],
case_path: str | None,
html_report: bool,
Expand All @@ -44,8 +45,6 @@ def startup(
**kwargs,
) -> None:
"""运行启动程序"""
if testcase_generate:
auto_generate_testcases()

run_args = [log_level]

Expand Down Expand Up @@ -146,8 +145,9 @@ def startup(
WeChat(test_result).send()

if allure:
if not os.path.exists(httpfpt_path.allure_report_env_file):
shutil.copyfile(httpfpt_path.allure_env_file, httpfpt_path.allure_report_env_file)
if os.path.exists(httpfpt_path.allure_report_dir):
if not os.path.exists(httpfpt_path.allure_report_env_file):
shutil.copyfile(httpfpt_path.allure_env_file, httpfpt_path.allure_report_env_file)

if allure_serve:
subprocess.run(
Expand All @@ -166,6 +166,7 @@ def run(
*args,
# auto testcases
testcase_generate: bool = False,
testcase_re_generation: bool = True,
# init
clean_cache: bool = False,
pydantic_verify: bool = True,
Expand All @@ -192,6 +193,7 @@ def run(

:param args: pytest 运行参数
:param testcase_generate: 自动生成测试用例(跳过同名文件),建议通过 CLI 手动执行,默认关闭
:param testcase_re_generation: 覆盖生成同名文件测试用例,建议通过 CLI 手动指定,默认开启
:param clean_cache: 清理 redis 缓存数据,对于脏数据,这很有用,默认关闭
:param pydantic_verify: 用例数据完整架构 pydantic 快速检测, 默认开启
:param args: pytest 运行参数
Expand All @@ -210,7 +212,7 @@ def run(
:return:
"""
try:
logo = """\n
logo = f"""\n
/$$ /$$ /$$$$$$$$ /$$$$$$$$ /$$$$$$$ /$$$$$$$$ /$$$$$$$ /$$$$$$$$
| $$ | $$|__ $$__/|__ $$__/| $$__ $$| $$_____/| $$__ $$|__ $$__/
| $$ | $$ | $$ | $$ | $$ | $$| $$ | $$ | $$ | $$
Expand All @@ -220,12 +222,19 @@ def run(
| $$ | $$ | $$ | $$ | $$ | $$ | $$ | $$
|__/ |__/ |__/ |__/ |__/ |__/ |__/ |__/

"""
Starting...
Version: {get_version(cli=False)}
"""
log.info(logo)
redis_client.init()
case_data.clean_cache_data(clean_cache)
case_data.case_data_init(pydantic_verify)
case_data.case_id_unique_verify()
if testcase_generate:
if not testcase_re_generation:
auto_generate_testcases()
else:
auto_generate_testcases(rewrite=True)
startup(
*args,
testcase_generate=testcase_generate,
Expand Down
6 changes: 4 additions & 2 deletions httpfpt/utils/cli/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from httpfpt.utils.rich_console import console


def get_version() -> None:
def get_version(cli: bool = True) -> None:
"""获取版本号"""
ver = read_text('httpfpt', '__init__.py')
mob = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", ver, re.MULTILINE)
if mob:
console.print(f'\n🔥 HttpFpt [cyan]{mob.group(1)}[/]')
if cli:
console.print('')
console.print(f'HTTPFPT: [cyan]{mob.group(1)}[/]')
else:
raise cappa.Exit('\n❌ 未查询到版本号', code=1)
Loading