From 8ed237ec2c3778c680f3cd8a8b9e8eb8fc3381a1 Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Thu, 29 Aug 2024 11:11:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dallure=E6=8B=B7=E8=B4=9D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httpfpt/run.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/httpfpt/run.py b/httpfpt/run.py index d0977d5..2dcf359 100644 --- a/httpfpt/run.py +++ b/httpfpt/run.py @@ -146,8 +146,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( From fc018a56401e917f25f96e77b6280edc7162894e Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Thu, 29 Aug 2024 11:33:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E9=A1=B9=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httpfpt/run.py | 18 +++++++++++++----- httpfpt/utils/cli/version.py | 6 ++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/httpfpt/run.py b/httpfpt/run.py index 2dcf359..1837724 100644 --- a/httpfpt/run.py +++ b/httpfpt/run.py @@ -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 @@ -29,7 +31,6 @@ def startup( *args, - testcase_generate: bool, log_level: Literal['-q', '-s', '-v', '-vv'], case_path: str | None, html_report: bool, @@ -44,8 +45,6 @@ def startup( **kwargs, ) -> None: """运行启动程序""" - if testcase_generate: - auto_generate_testcases() run_args = [log_level] @@ -167,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, @@ -193,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 运行参数 @@ -211,7 +212,7 @@ def run( :return: """ try: - logo = """\n + logo = f"""\n /$$ /$$ /$$$$$$$$ /$$$$$$$$ /$$$$$$$ /$$$$$$$$ /$$$$$$$ /$$$$$$$$ | $$ | $$|__ $$__/|__ $$__/| $$__ $$| $$_____/| $$__ $$|__ $$__/ | $$ | $$ | $$ | $$ | $$ | $$| $$ | $$ | $$ | $$ @@ -221,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, diff --git a/httpfpt/utils/cli/version.py b/httpfpt/utils/cli/version.py index f5197d0..4b79ea6 100644 --- a/httpfpt/utils/cli/version.py +++ b/httpfpt/utils/cli/version.py @@ -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)