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,直至成功
遇到問題
-
執行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
-
調用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')