天天看點

Linux pytest +allure 運作遇到的坑

1.Python3 run.py  無法運作pytest架構

伺服器安裝:

pip install pytest

。我也能用Python導入庫 

解決方法:

python -m pytest 

python3 -m pytest  --html=%s/report.html --self-contained-html  --alluredir %s 
           

2.allure運作報錯 “ValueError: option names {'--alluredir'} already added”

問題排查:

依賴包沖突 

pytest-allure-adaptor與allure-pytest的alluredir都被引用造成沖突

解決辦法: 

需要解除安裝不用的包 :pip uninstall pytest-allure-adaptor

3.腳本執行完成後 不生成allure 報告

問題排查:

通過列印運作時系統PATH變量,發現Python在運作的時候 沒有加載系統環境變量

解決辦法:

代碼内手動增加環境變量寫入,使運作的時候自動添加運作環境變量

path = "/usr/bin:/usr/local/sbin:/usr/sbin:/home/jenkinsx/.local/bin:/home/jenkinsx/bin:/home/jenkinsx/workspace/allure-2.13.8/bin"
        shell.invoke(cmd, env={"PATH": path})


class Shell:
    @staticmethod
    def invoke(cmd, env={}):
        output, errors = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env).communicate()
        o = output.decode("utf-8")
        return o