如何让 Allure 在 Python gitlab docker 上运行

问题描述 投票:0回答:1

我正在尝试使用 python docker 映像在 gitlab 上运行我的剧作家 python 项目。我已经设法让它运行,但是,一旦测试套件运行,我就会使用 allure 来生成报告。这在我的个人桌面环境上运行得非常好。然而,现在我已经将它移至 gitlab,我无法在最后生成诱惑报告。

我已经附加了 gitlab 的 yaml 文件,但是当尝试运行任何 allure 命令时,它显示“allure:未找到”或“allure:未找到命令”。如果您能提供任何帮助来使其正常工作,我们将不胜感激。

image: python:3.12

variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

cache:
  paths:
    - .cache/pip

before_script:
  - python --version ; pip --version  # For debugging
  - pip install virtualenv
  - virtualenv venv
  - source venv/bin/activate
  - pip install 'nodejs-bin[cmd]'
  - npm install -g allure-commandline
  - allure --version
  - pip install -r requirements.txt # Installs the required dependencies before running
  - playwright install
  - playwright install-deps
  - pip list # Verify the dependencies

stages:          # List of stages for jobs, and their order of execution
  - deploy
  - generate_allure_results
  - upload_results


AutomatedRegression: # Deployment and running of the feature files
    stage: deploy
    script:
        - behave features
    allow_failure: true

ParseTestResults: # Parsing test results
    stage: generate_allure_results
    script: "Parsing results..."
    needs:
      - job: AutomatedRegression


UploadResults: # Uploading results file to JIRA ticket?
    stage: upload_results
    script: "Some script needed here to upload test results into a Jira ticket?"
    needs:
      - job: ParseTestResults
python docker gitlab allure playwright-python
1个回答
0
投票

看来该问题可能与 GitLab CI 环境中 Allure 命令行工具的安装或路径配置有关。您可以尝试执行以下几个步骤来解决此问题:

  1. 确保 Allure 安装正确

    • 确保
      npm install -g allure-commandline
      命令执行成功。您可以添加检查来确认安装:
      before_script:
        - python --version ; pip --version  # For debugging
        - pip install virtualenv
        - virtualenv venv
        - source venv/bin/activate
        - pip install 'nodejs-bin[cmd]'
        - npm install -g allure-commandline
        - allure --version || echo "Allure installation failed"
        - pip install -r requirements.txt # Installs the required dependencies before running
        - playwright install
        - playwright install-deps
        - pip list # Verify the dependencies
      
  2. 将 Allure 添加到路径:

    • 确保Allure安装目录已添加到PATH环境变量中。您可以通过修改
      before_script
      部分来做到这一点:
      before_script:
        - python --version ; pip --version  # For debugging
        - pip install virtualenv
        - virtualenv venv
        - source venv/bin/activate
        - pip install 'nodejs-bin[cmd]'
        - npm install -g allure-commandline
        - export PATH=$PATH:/root/.npm-global/bin
        - allure --version
        - pip install -r requirements.txt # Installs the required dependencies before running
        - playwright install
        - playwright install-deps
        - pip list # Verify the dependencies
      
  3. 检查Allure安装目录

    • 验证 Allure 的安装目录并确保它在您的 PATH 中正确引用。您可以通过运行
      npm root -g
      并将其添加到 PATH 来找到安装目录。
  4. 使用自定义 Docker 镜像:

    • 如果上述步骤不起作用,请考虑创建一个预装 Allure 的自定义 Docker 镜像。这可以帮助确保所有依赖项在 CI 环境中可用。
© www.soinside.com 2019 - 2024. All rights reserved.