【发布时间】:2020-07-11 05:20:42
【问题描述】:
我想创建一个执行以下操作的 Github 工作流:
- 用
pytest测试我的代码 - 触发 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