歡迎關(guān)注我公眾號呀~「測試游記」「zx94_11」
Python隔離環(huán)境搭建
- 安裝Pyenv Pipeline插件
- 在Jenkins機器上安裝python,pip,virtualenv
??由于使用虛擬環(huán)境搭建,所以沒有第三方的庫,如果需要使用請使用pip來進行安裝
導出現(xiàn)在環(huán)境的第三方庫
pip freeze > 「xxxx.txt」
批量安裝第三方庫:
pip install -r 「xxxx.txt」
第三方庫
插件安裝
在流水線中使用Pyenv Pipeline插件提供的withPythonEnv
方法
小括號內(nèi)為可執(zhí)行python路徑。流水線會在當前工作空間下創(chuàng)建一個virtualenv環(huán)境
大括號內(nèi)的內(nèi)容就執(zhí)行在新建的virtualenv環(huán)境下
python3路徑
withPythonEnv('/usr/lib/python3'){
sh 'python --version' //查看python版本
}
Allure報告
- 安裝Allure Jenkins插件
- 配置Allure自動安裝
- 編寫pytest腳本
- 執(zhí)行
- 查看結(jié)果
安裝插件
image-20190713142000087
使用片段生成器輔助步驟的生成
自動生成
下面是流水線部分
由于只編寫了簡單的測試腳本,所以只需要安裝pytest
和allure-pytest
兩個第三方庫就可以了
最后使用post-always來進行allure報告的展示
報告的鏈接圖標會展示在該任務中
pipeline{
agent any
stages{
stage('Example'){
steps{
withPythonEnv('/usr/bin/python'){
sh 'python -m pip install pytest '
sh 'python -m pip install allure-pytest'
sh 'python -m pytest -v test_allure.py --alluredir=allure-results'
}
exit 0
}
}
}
post{
always{
allure includeProperties: false, jdk: '', results: [[path: 'allure-results']]
}
}
}
pytest腳本:
import pytest
def test_success():
"""this test succeeds"""
assert True
def test_failure():
"""this test fails"""
assert False
def test_skip():
"""this test is skipped"""
pytest.skip('for a reason!')
def test_broken():
raise Exception('oops')
虛擬環(huán)境中正在安裝第三方庫
環(huán)境部分
使用pytest進行測試,并輸出報告至allure-results
測試部分
報告的鏈接圖標??????
測試結(jié)果
具體的報告??
Allure報告
小結(jié)
綜上,
在執(zhí)行的設備上搭建了python,pip,virtualenv環(huán)境
在Jenkins上配置了自動安裝Allure
完成了環(huán)境隔離,測試執(zhí)行,報告展示