路径兼容windows运行方式
This commit is contained in:
parent
97e4bf253a
commit
2ab2ea9232
|
@ -12,6 +12,7 @@ import time
|
|||
import colorlog
|
||||
|
||||
from common.settings import LOG_DEBUG
|
||||
from configs.dir_path_config import LOGS_DIR
|
||||
|
||||
|
||||
class ColoredFormatter(logging.Formatter):
|
||||
|
@ -61,8 +62,9 @@ class Logger:
|
|||
|
||||
# 设置日志存储路径
|
||||
if not cls._log_path:
|
||||
file_path = os.path.abspath(
|
||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), '../outFiles/logs'))
|
||||
# file_path = os.path.abspath(
|
||||
# os.path.join(os.path.dirname(os.path.abspath(__file__)), '../outFiles/logs'))
|
||||
file_path = LOGS_DIR
|
||||
dir_name = time.strftime('%Y-%m-%d')
|
||||
file_name = time.strftime('%Y-%m-%d %H:%M:%S') + '-' + 'log.log'
|
||||
if not os.path.exists(os.path.join(file_path, dir_name)):
|
||||
|
|
|
@ -29,8 +29,8 @@ LOGS_DIR = os.path.join(OUT_FILES_DIR, 'logs')
|
|||
PYTEST_REPORT_DIR = os.path.join(OUT_FILES_DIR, 'pytest_report')
|
||||
# pytest_result目录的路径
|
||||
PYTEST_RESULT_DIR = os.path.join(OUT_FILES_DIR, 'pytest_result')
|
||||
# report目录的路径
|
||||
REPORT_DIR = os.path.join(OUT_FILES_DIR, 'report')
|
||||
# allure_report目录的路径
|
||||
ALLURE_REPORT_DIR = os.path.join(OUT_FILES_DIR, 'allure_report')
|
||||
# screeShot目录的路径
|
||||
SCREENSHOT_DIR = os.path.join(OUT_FILES_DIR, 'screeShot')
|
||||
# Temp目录的路径
|
||||
|
|
23
run.py
23
run.py
|
@ -19,7 +19,8 @@ from utils.command_parser import command_parser
|
|||
from common.mail_sender import MailSender
|
||||
from common.robot_sender import EnterpriseWechatNotification
|
||||
from common.settings import IS_SEND_EMAIL, IS_SEND_WECHAT
|
||||
from configs.dir_path_config import BASE_DIR
|
||||
from configs.dir_path_config import BASE_DIR, TEMP_DIR, ALLURE_REPORT_DIR, PYTEST_REPORT_DIR, CONFIGS_DIR, \
|
||||
PYTEST_RESULT_DIR
|
||||
from utils.yaml_handle import YamlHandle
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -42,10 +43,10 @@ if __name__ == '__main__':
|
|||
# '-q', # 代表 "quiet",即安静模式,它可以将 pytest 的输出精简化,只输出测试用例的执行结果,而不会输出额外的信息,如测试用例的名称、执行时间等等
|
||||
# '-vs', # 指定输出用例执行信息,并打印程序中的print/logging输出
|
||||
'testCase/', # 执行用例的目录
|
||||
'--alluredir', f'{BASE_DIR}/Temp', '--clean-alluredir', # 先清空旧的alluredir目录,再将生成Allure原始报告需要的数据,并存放在 /Temp 目录
|
||||
f'--html={BASE_DIR}/outFiles/pytest_report/pytest_report.html', # 指定pytest-html报告的存放位置
|
||||
'--alluredir', f'{TEMP_DIR}', '--clean-alluredir', # 先清空旧的alluredir目录,再将生成Allure原始报告需要的数据,并存放在 /Temp 目录
|
||||
f'--html={os.path.join(PYTEST_REPORT_DIR, "pytest_report.html")}', # 指定pytest-html报告的存放位置
|
||||
'--json-report', '--json-report-summary', # 生成简化版json报告
|
||||
f'--json-report-file={BASE_DIR}/outFiles/pytest_result/pytest_result.json', # 指定json报告存放位置
|
||||
f'--json-report-file={os.path.join(PYTEST_RESULT_DIR, "pytest_result.json")}', # 指定json报告存放位置
|
||||
'--self-contained-html', # 将css样式合并到pytest-html报告文件中,便于发送邮件
|
||||
'--capture=no', # 捕获stderr和stdout,这里是使pytest-html中失败的case展示错误日志,会导致case中的print不打印
|
||||
# '-p', 'no:logging', # 表示禁用logging插件,使报告中不显示log信息,只会显示stderr和stdoyt信息,避免log和stderr重复。
|
||||
|
@ -56,14 +57,14 @@ if __name__ == '__main__':
|
|||
|
||||
###################发送allure报告
|
||||
# allure报告展示environment时所需要的数据,这里是在项目根路径下创建的environment.properties文件拷贝到allure-report报告中,保证环境文件不会被清空
|
||||
shutil.copy(BASE_DIR + '/environment.properties', BASE_DIR + '/Temp/environment.properties')
|
||||
shutil.copy(BASE_DIR + os.sep + 'environment.properties', TEMP_DIR + os.sep + 'environment.properties')
|
||||
# allure报告展示运行器时所需要的数据
|
||||
shutil.copy(BASE_DIR + '/executor.json', BASE_DIR + '/Temp/executor.json')
|
||||
shutil.copy(BASE_DIR + os.sep + 'executor.json', TEMP_DIR + os.sep + 'executor.json')
|
||||
# 使用allure generate -o 命令将./Temp目录下的临时报告生成到Report目录下变成html报告
|
||||
os.system(f'allure generate {BASE_DIR}/Temp -o {BASE_DIR}/outFiles/allure_report --clean')
|
||||
os.system(f'allure generate {TEMP_DIR} -o {ALLURE_REPORT_DIR} --clean')
|
||||
# 将本地启动脚本和查看allure报告方法放入报告目录下面
|
||||
shutil.copy(BASE_DIR + '/open_report.sh', BASE_DIR + '/outFiles/allure_report/open_report.sh')
|
||||
shutil.copy(BASE_DIR + '/查看allure报告方法', BASE_DIR + '/outFiles/allure_report/查看allure报告方法')
|
||||
shutil.copy(BASE_DIR + os.sep + 'open_report.sh', ALLURE_REPORT_DIR + os.sep + 'open_report.sh')
|
||||
shutil.copy(BASE_DIR + os.sep + '查看allure报告方法', ALLURE_REPORT_DIR + os.sep + '查看allure报告方法')
|
||||
|
||||
# 发送企业微信群聊
|
||||
if IS_SEND_WECHAT: # 判断是否需要发送企业微信
|
||||
|
@ -74,11 +75,11 @@ if __name__ == '__main__':
|
|||
|
||||
# 发送邮件
|
||||
if IS_SEND_EMAIL: # 判断是否需要发送邮件
|
||||
file_path = '/Users/wangjie/SensoroApi/outFiles/pytest_report/pytest_report.html'
|
||||
file_path = PYTEST_REPORT_DIR + os.sep + 'pytest_report.html'
|
||||
with open(file_path, 'rb') as f:
|
||||
text_to_send = f.read()
|
||||
|
||||
config = YamlHandle('configs/mail_config.yaml').read_yaml()
|
||||
config = YamlHandle(CONFIGS_DIR + os.sep + 'mail_config.yaml').read_yaml()
|
||||
ms = MailSender(
|
||||
mail_subject=config['mail_subject'],
|
||||
sender_mail_address=config['sender_mail_address'],
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding:utf-8 -*-
|
||||
import os
|
||||
|
||||
import allure
|
||||
import pytest
|
||||
|
||||
from configs.dir_path_config import DATAS_DIR
|
||||
from pageApi.login import Login
|
||||
from utils.yaml_handle import YamlHandle
|
||||
|
||||
|
||||
@allure.feature("登录模块")
|
||||
class TestLogin:
|
||||
data_smsCode = YamlHandle('datas/smsCode.yaml').read_yaml()
|
||||
data_smsCode = YamlHandle(DATAS_DIR+os.sep+'smsCode.yaml').read_yaml()
|
||||
params = [(item['case_title'], item['expected']) for item in data_smsCode]
|
||||
|
||||
@allure.story("测试获取验证码")
|
||||
|
@ -24,7 +27,7 @@ class TestLogin:
|
|||
r = "获取验证码成功"
|
||||
assert r == message
|
||||
|
||||
data_login = YamlHandle('datas/login.yaml').read_yaml()
|
||||
data_login = YamlHandle(DATAS_DIR+os.sep+'login.yaml').read_yaml()
|
||||
params = [(item['case_title'], item['username'], item['password'], item['expected']) for item in data_login]
|
||||
|
||||
@allure.story("测试登录")
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
# @File : report_data_handle.py
|
||||
# @project : SensoroApi
|
||||
import json
|
||||
import os
|
||||
|
||||
from configs.dir_path_config import BASE_DIR
|
||||
from configs.dir_path_config import BASE_DIR, PYTEST_RESULT_DIR
|
||||
|
||||
|
||||
class ReportDataHandle:
|
||||
|
@ -20,7 +21,7 @@ class ReportDataHandle:
|
|||
@staticmethod
|
||||
def pytest_json_report_case_count():
|
||||
"""统计pytest_json_report报告收集的case数量"""
|
||||
with open(BASE_DIR + '/outFiles/pytest_result/pytest_result.json', 'r', encoding='utf-8') as f:
|
||||
with open(PYTEST_RESULT_DIR + os.sep+'pytest_result.json', 'r', encoding='utf-8') as f:
|
||||
pytest_result = json.loads(f.read())
|
||||
case_count = {}
|
||||
case_count["total_case"] = pytest_result['summary'].get("total", 0) # 用例总数
|
||||
|
|
Loading…
Reference in New Issue