【问题标题】:Github Actions, Python Coverage and Sonar QubeGithub Actions、Python Coverage 和 Sonar Qube
【发布时间】:2020-07-11 05:20:42
【问题描述】:

我想创建一个执行以下操作的 Github 工作流:

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

据我了解,SonarQ 需要一个文件coverage.xml 来显示代码覆盖率。这可以生成

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

根据this articlecoverage.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】:

错误来自sonar-project.properties 文件中reportPaths 中缺少的s

【讨论】:

  • 感谢您的回复,我正在努力解决这个问题。如果我得到任何解决方案,我会在这里发布。
猜你喜欢
  • 1970-01-01
  • 2018-07-27
  • 2018-01-27
  • 1970-01-01
  • 1970-01-01
  • 2016-06-01
  • 2016-10-25
  • 2021-12-16
  • 2018-07-12
相关资源
最近更新 更多