Jenkins(六)

歡迎關(guān)注我公眾號呀~「測試游記」「zx94_11」

Python隔離環(huán)境搭建

  1. 安裝Pyenv Pipeline插件
  2. 在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報告

  1. 安裝Allure Jenkins插件
  2. 配置Allure自動安裝
  3. 編寫pytest腳本
  4. 執(zhí)行
  5. 查看結(jié)果
安裝插件
image-20190713142000087

使用片段生成器輔助步驟的生成

自動生成

下面是流水線部分

由于只編寫了簡單的測試腳本,所以只需要安裝pytestallure-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í)行報告展示

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容