Python project code coverage badge with coveralls / github actions
Asked Answered
I

1

8

I'm trying to add a code coverage % badge to my repos README.md

I'm currently using Github actions to automate my pytest testing. I had that working on its own, but ive been struggling trying to get the coverage % badge. I am using coveralls for the badge generation, and based on it looks like coveralls is expecting an lcov.info file. But when I look at the reporting options for pytest-cov I don't see an output option for that.

I've tried generating other types such as xml and configuring to look for this but it still looks for the lcov.info in the coverage folder. below is my current pythonapp.yml file. the current step that fails is the coveralls with it looking for ./coverage/lcov.info

Any assistance on what im doing wrong or how to fix would be greatly appreciated.

name: tests

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - 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
    - name: Lint with flake8
      run: |
        pip install flake8
        # stop the build if there are Python syntax errors or undefined names
        flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
        # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
    - name: Test with pytest
      run: |
        pip install pytest pytest-cov
        python -m pytest --cov=./myapp --cov-report xml
    - name: Coveralls
      uses: coverallsapp/github-action@master
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        path--to-lcov: coverage.xml
Interfaith answered 29/3, 2020 at 6:12 Comment(6)
from this issue I think you can't use coverallsapp/github-action with pytest because it doesn't output lcov file. The issue points out that using the coveralls python library would work but not with a forked PR which may be your case (or not)Leyes
Also looking at the javascript coveralls library which is called by the coveralls task itself seems to only support lcovLeyes
I think your answer may be in this post you will need to use a forked version of coveralls-python instead of coverallsapp/github-actionLeyes
v helpful, thank you. i was able to get it to work with the first link.Interfaith
@Interfaith since you seem to have a working solution... how about posting it?Churning
You can get pytest to output an lcov file. See the last example in this documentation. This made it work for me.Kelbee
P
5

Looks to me like you have an extra hyphen in the name of the argument for "path-to-lcov"

According to the docs here: https://github.com/marketplace/actions/coveralls-github-action

Try changing "path--to-lcov" to "path-to-lcov"

Petuu answered 18/4, 2021 at 21:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.