【python】连接Jira获取token以及jira对象
【python】解析自动化脚本文件并按照=测试周期=存储记录
【python】向Jira推送自动化用例执行成功
【python】向Jira测试计划下,附件中增加html测试报告
将pytest生成的测试报告中css内容,写到html中,为一个文件,方便报告上传jira
css文件路径可以写死,因为固定不变,html会编辑后重新命名!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2025-02-14 14:31
# @Author : duxiaowei
# @File : report_css_into_html.py
# @Software: 将报告中的css文件插入到html文件中,方便jira下载查看
import os
def rewrite_html(html_file_path):
path_html = os.path.abspath('..') + '\\test_API\\reports\\' + html_file_path
path_css = os.path.abspath('..') + '\\test_API\\reports\\assets\\style.css'
try:
# 读取 HTML 文件内容
with open(path_html, 'r', encoding='GB2312') as html_file:
html_content = html_file.read()
# 读取 CSS 文件内容
with open(path_css, 'r', encoding='GB2312') as path_css:
css_content = path_css.read()
# 定义要查找的 <link> 标签
link_tag = '<link href="assets/style.css" rel="stylesheet" type="text/css"/>'
# 生成新的 <style> 标签内容
style_tag = f'<style>\n{css_content}\n</style>'
# 替换 <link> 标签为 <style> 标签
new_html_content = html_content.replace(link_tag, style_tag)
# 将修改后的内容写回 HTML 文件
with open(path_html, 'w', encoding='GB2312') as html_file:
html_file.write(new_html_content)
print("CSS 文件内容已成功插入到 HTML 文件中。")
except FileNotFoundError:
print("未找到 HTML 或 CSS 文件,请检查文件路径。")
except Exception as e:
print(f"处理文件时出现错误: {e}")