Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coveralls reporting fails as it keeps throwing error Failed to parse string #1610

Open
jvkumar opened this issue Jan 9, 2022 · 4 comments
Open

Comments

@jvkumar
Copy link

jvkumar commented Jan 9, 2022

I have the following configuration set up in my GH action. I have a Python flask app repo that uses pytest to run the test

- name: Coveralls GitHub Action
  uses: coverallsapp/github-action@1.1.3
  with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        path-to-lcov: ./coveralls/lcov.info

And I created an empty file ./coveralls/lcov.info as shown here https://share.getcloudapp.com/5zunyjmp

On GH action after successfully running all my tests, when it is time to send info to coveralls, I get these

Run coverallsapp/github-action@1.1.3
  with:
    github-token: ***
    path-to-lcov: ./coveralls/lcov.info
    coveralls-endpoint: https://coveralls.io
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.0/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.0/x64/lib
Using lcov file: ./coveralls/lcov.info
Error:  "2022-01-09T21:37:43.411Z"  'error from lcovParse: ' 'Failed to parse string'
Error:  "2022-01-09T21:37:43.412Z"  'input: ' ''
Error:  "2022-01-09T21:37:43.412Z"  'error from convertLcovToCoveralls'
Error: Failed to parse string

May I know what am I doing wrong or any way to debug it to provide you more info in the troubleshooting or is it something wrong in coveralls?

btw, my test running commands are as follows (if that helps in troubleshooting) -

docker-compose run my_cool_service-api py.test -v tests/ \
		--cov=src \
		--cov-report term \
		--cov-report term-missing \
		--cov-report html
docker-compose stop

I also have a .coveragerc file on the root level, which contains

[report]

[html]
directory = test_reports/htmlcov

[run]
data_file = test_reports/.coverage
@afinetooth
Copy link
Collaborator

afinetooth commented Jan 10, 2022

Hi @jvkumar. Yes, that's the result you can expect if you pass an empty lcov file to the Coveralls Github Action.

Here's why:

Then the errors that bubble up are the ones you see:

Using lcov file: ./coveralls/lcov.info
Error: "2022-01-09T21:37:43.411Z" 'error from lcovParse: ' 'Failed to parse string'
Error: "2022-01-09T21:37:43.412Z" 'input: ' ''
Error: "2022-01-09T21:37:43.412Z" 'error from convertLcovToCoveralls'
Error: Failed to parse string

You might get different behavior if your file contained an empty, but fully formed, JSON object, like {}. But since it's just an empty string, the lcov-parse package throws the error, Failed to parse file.

Can I ask why your lcov file is empty? Is that what you're expecting, or the use case you're trying to validate?

If not, the fix would be to make sure pystest is generating a code coverage report in lcov format, which it populates into ./coveralls/lcov.info.

@jvkumar
Copy link
Author

jvkumar commented Jan 22, 2022

@afinetooth thank you for your reply. Please see my notes below.

Can I ask why your lcov file is empty? Is that what you're expecting, or the use case you're trying to validate?

It is because pytest cov is can create coverage reports only in one of these formats - The available reports are terminal (with or without missing line numbers shown), HTML, XML, and annotated source code.

If not, the fix would be to make sure pystest is generating a code coverage report in lcov format, which it populates into ./coveralls/lcov.info.

As I said above, pytest doesn't produce coverage reports in lcov format . So what is the solution here?

@afinetooth
Copy link
Collaborator

@jvkumar I see. Yes, some languages use code coverage libraries that export their own format.

In this case, in your shoes, I'd use a language integration specific to python, like one of these.

Of those, coveralls-python is most used and well-maintained.

The documentation for that integration has a section on using it with Github Actions.

You'll also do well to check the issues for that project if you run into problems, as it's actively supported.

There's also a Coveralls Python Github Action, but I'm not as familiar with it to make a recommendation.

Maybe try those and let us know if you hit any issue you can't find a solution for those project's issue boards.

@0hsn
Copy link

0hsn commented Mar 1, 2023

Hey everyone. Bit late to the discussion.

I used coverage-lcov to generate LCOV file.

This is how I implemented for my python repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants