jenkins+pytest+allure

python 项目目录结构

MobileAutomation 项目结构
MobileAutomation
├─ Basefunctest
│  │  __init__.py
│  │
│  ├─ iOS
│  │  │  conftest.py
│  │  │  main.py
│  │  │  test_create_blank_pdf.py
│  │  │  test_file_to_pdf.py
│  │  │  test_merge_pdf.py
│  │  │  test_scan.py
│  │  │  test_web_to_pdf.py
│  │  │  __init__.py
│  │  │
│  │  ├─ common
│  │  │      data_operator.py
│  │  │      func_operator.py
│  │  │      web_operator.py
│  │  │      __init__.py
│  │  │
│  │  └─ page
│  │  │      base_page.py
│  │  │      blank_pdf_page.py
│  │  │      file_content_page.py
│  │  │      locator.py
│  │  │      main_page.py
│  │  │      page_operator.py
│  │  │      scan_page.py
│  │  │      web_to_pdf_page.py
│  │  │      __init__.py
│  │  │
│  │  └─ report
│  │  │      allure_report
│  │  │      allure_result_file
│  │  │
│  └─ tools
│      └─ allure-2.13.9
│          ├─ bin
│          │      allure
│          │      allure.bat
│          │
│          ├─ config
│          │      allure-cucumber.yml
│          │      allure-junit.yml
│          │      allure.yml
│          │
测试入口的 main.py
# coding=utf-8
# !/usr/bin/env python
# description: execute tests entrance
import os
import shutil
from common import data_operator
from common import func_operator

if __name__ == '__main__':
    report_path = os.path.join(data_operator.WORK_SPACE, 'Basefunctest', 'iOS', 'report')
    print(f"report_path:{report_path}")
    # clear report directory
    if os.path.exists(report_path):
        shutil.rmtree(report_path)
        os.mkdir(report_path)
    allure_result_file = './report/allure_result_file'
    allure_report = './report/allure_report'
    execute_str = f"python3 -m pytest --alluredir {allure_result_file}"

    # check jenkins environ
    environ_dict = os.environ
    build_url = environ_dict.get('BUILD_URL')
    print(f"jenkins build url:{build_url}")

    # run main.py on jenkins
    if build_url:
        allure_url = ''.join([build_url, 'allure'])
        print(f"jenkins allure url:{allure_url}")
        os.system(execute_str)

    # run main.py local
    else:
        ip = func_operator.get_host_ip()
        port = func_operator.get_free_port(8000, 9000)
        print(f"allure server port:{port}")
        allure_path = '../tools/allure-2.13.9/bin/allure'
        os.system(execute_str)
        os.system(f"{allure_path} generate {allure_result_file} -o {allure_report} --clean")
        os.system(f"{allure_path} open -h {ip} -p {port} {allure_report}")

jenkins 配置

新建一个节点

当前测试的 iOS 工程需要在 mac 电脑上跑,所以需要在 mac 上搭建一个节点。
在这里插入图片描述
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-44rSUFFy-1625570438320)(mdpic\jenkins+pytest+allure2.png)]
在这里插入图片描述

启动节点

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-htBLzLGp-1625570438325)(mdpic\jenkins+pytest+allure5.png)]


新建一个项目
配置要运行的节点标签

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uBlwdCKC-1625570438326)(mdpic\jenkins+pytest+allure7.png)]

配置git

添加密码,创建子目录(名字为git的项目名)。其中有一些配置是需要安装jenkins插件的。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uzV4CctW-1625570438326)(mdpic\jenkins+pytest+allure8.png)]在这里插入图片描述

配置build

选择了用shell脚本的方式触发测试
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-zl9JmQSL-1625570438327)(mdpic\jenkins+pytest+allure10.png)]

配置allure插件

和项目中的 main.py 文件中的代码相匹配:测试产生的 allure 文件存在路径、生成报告的路径
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OeNCdpgr-1625570438328)(mdpic\jenkins+pytest+allure11.png)]在这里插入图片描述

展示

在这里插入图片描述在这里插入图片描述在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值