Github行为,Python覆盖和Sonar Qube。

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

我想创建一个Github工作流,做以下工作。

  1. 用以下方法测试我的代码 pytest
  2. 触发Sonar Qube Cloud分析到代码,并显示我的测试覆盖率!

据我所知,SonarQ需要一个文件 coverage.xml 来显示代码覆盖率。这可以通过

pytest --cov=./ --cov-report=xml --doctest-modules

根据 本文 coverage.xml 应可在 /github/workspace/coverage.xml.

因此,我指定我的 sonar-project.properties 在项目的根目录下。

sonar.organization=pokemate
sonar.projectKey=PokeMate_name-generator
sonar.sources=.
sonar.python.coverage.reportPath=/github/workspace/coverage.xml

我的动作文件 build.yml:

on:
  push:
    branches:
      - master
      - develop
      - sonar-qube-setup

jobs:
  build:
    runs-on:
      - ubuntu-latest

    steps:
      # Checkout repo
      - uses: actions/checkout@v2

      # Dependencies
      - name: Set up Python 3.7
        uses: actions/setup-python@v1
        with:
          python-version: 3.7

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt

      # Test
      - name: Test with pytest
        run: |
          pytest --cov=./ --cov-report=xml --doctest-modules

      # Sonar Qube
      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

然而,在SonarQ上,它仍然显示出0%的测试覆盖率,这可能是由于它找不到 coverage.xml. 有什么办法可以让这个工作?

sonarqube pytest github-actions
1个回答
1
投票

错误来自于缺失 sreportPathssonar-project.properties 文件。

© www.soinside.com 2019 - 2024. All rights reserved.