- all.py:主运行程序

import os
import time
import pytest
if __name__ == '__main__':
pytest.main()
time.sleep(1)
os.system("copy environment.properties .\\reports\\temp")
os.system("allure generate ./reports/temp -o ./reports/allure --clean")
import json
def set_report_title(json_file_path, key, new_value):
with open(json_file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
data['reportName'] = new_value
with open(json_file_path, 'w', encoding='utf-8') as file:
json.dump(data, file, ensure_ascii=False, indent=4)
json_file_path = r'./reports/allure/widgets/summary.json'
set_report_title(json_file_path, 'reportName', 'XX互联财务接口自动化测试报告')
import pytest
from common.yaml_util import clean_file
@pytest.fixture(scope='session',autouse=True)
def clean_extract():
clean_file('/config/extract.yml')
- debugtalk.py:热加载文件,用于封装常用函数
import random
from common.yaml_util import read_file
class DebugTalk:
def get_random_number(self,mix,max):
return random.randint(int(mix),int(max))
def get_base_url(self,one_node):
return read_file('/config/config.yml','base',one_node)
- environment.properties:生成Allure报告展示环境数据
Author=zhangweixu
ProjectName=FenMiApiFrame
BaseUrl=https://XXXX.com
GitLab=http://XXXX:8010/root/fenmi_api_frame
PythonVersion=3.7.0
PytestVersion=7.4.4
AllureVersion=2.18.1
[pytest]
; addopts = -vs --alluredir=reports/temp
addopts = -vs --alluredir=reports/temp --clean-alluredir
; addopts = -vs --html=reports/report.html
testpaths = testcases/fenmi testcases/hlj_sec
; testpaths = testcases/fenmi testcases/weixin testcases/Zgen testcases/hlj_sec
python_files = test_*.py
python_classes = Test*
python_functions = test_*