allure+jenkins+pytest


allure+jenkins+pytest

jenkins配置

1、jenkins -> 系统管理 -> 插件管理 -> 可选插件中过滤Allure,勾选对应插件安装

2、安装完插件后,继续在jenkins-> Global Tool Configuration中安装Allure Commandline,该安装会在工程构建时联网下载安装

3、工程qiekj-ui-autotest配置,构建执行shell命令:/usr/local/bin/pytest --alluredir [xml_report_path]

​ 增加构建后操作,allure report ---->> path 与构建命令中的[xml_report_path]相同

Execute shell  /usr/local/bin/py.test --alluredir report -W ignore --reruns 3

如果失败,则重复执行3遍case,直至成功

遇到问题
  1. 执行shell命令:pytest --alluredir report 报错, pytest: command not found Build

    解决办法:参考https://blog.csdn.net/lhh08hasee/article/details/80819244

    • 在Jenkins所在的linux服务器中使用命令which pytest,找到pytest命令的路径 (我找到的路径为/root/anaconda2/bin/pytest)
    • 在jenkins命令中更改为 /usr/local/bin/pytest --alluredir report
  2. 调用config模块中config配置URL,报错,

    \qiekj-ui-autotest
      config/
        config.py
      src/
        test/
          qiekj/
            qieoperator/
    		  test_operator.py
               __init__.py
    
    # test_operator.py
    from config import config
    
    # config.py
    operatorURL = 'test-bm.qiekj.com'
    
    _____ ERROR collecting src/test/qiekj/qieoperator/test_operator_login.py ______
    ImportError while importing test module 'D:\work\qiekj-ui-autotest\src\test\qiekj\qieoperator\test_operator_login.py'.
    Hint: make sure your test modules/packages have valid Python names.
    Traceback:
    src\test\qiekj\qieoperator\test_operator_login.py:4: in <module>
        from config import config
    E   ModuleNotFoundError: No module named 'config'
    
    解决办法:参考https://github.com/pytest-dev/pytest/issues/2421
    
# operator/__init__.py
import sys
sys.path.append('/var/lib/jenkins/workspace/qiekj-ui-autotest')
#sys.path.append('D:\work\qiekj-ui-autotest')


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM