MishaKav / pytest-coverage-comment

Comments a pull request with the pytest code coverage badge and full report
MIT License
182 stars 60 forks source link

File read successfully "/home/runner/work/repo-name/repo-name/./pytest-coverage.txt" Error: Coverage file "/home/runner/work/repo-name/repo-name/./pytest-coverage.txt" has bad format or wrong data #146

Closed NorhanAlg closed 11 months ago

NorhanAlg commented 1 year ago

when i run pytest, i don't get any warrnings

This is the command i use for pytest pytest -v --color=yes --cov-report "xml:coverage.xml" --junitxml=pytest.xml --cov=. tests/integration_tests/ | tee pytest-coverage.txt

this is the comment section

    - name: Pytest coverage comment
      uses: MishaKav/pytest-coverage-comment@main
      with:
        pytest-coverage-path: pytest-coverage.txt
        junitxml-path: pytest.xml

i keep getting from generating the comment File read successfully "/home/runner/work/repo-name/repo-name/./pytest-coverage.txt" Error: Coverage file "/home/runner/work/repo-name/repo-name/./pytest-coverage.txt" has bad format or wrong data

MishaKav commented 1 year ago

It looks like your file has a bad format or empty, try to identify what exists inside the file.

I can suggest running simple cat command, to see the content of the file, something like:

  - name: check content file
    run: cat ./pytest-coverage.txt

The format of file will be good if it contains every word like this https://github.com/MishaKav/pytest-coverage-comment/blob/main/src/parse.js#L10-L18

MishaKav commented 1 year ago

any updates?

filipegalo commented 11 months ago

I have the same problem. Result of the cat:

Run cat ./backend/pytest-coverage.txt
============================= test session starts ==============================
platform linux -- Python 3.11.[7](https://github.com/filipegalo/trfu/actions/runs/7152602668/job/19478100775#step:7:8), pytest-7.4.1, pluggy-1.3.0
rootdir: /home/runner/work/trfu/trfu/backend
configfile: pytest.ini
plugins: cov-4.1.0, flask-1.2.0, mock-3.12.0
collected 23 items

tests/auth/test_auth_route.py .............                              [ 56%]
tests/package/test_package_route.py ..........                           [100%]

------ generated xml file: /home/runner/work/trfu/trfu/backend/pytest.xml ------

---------- coverage: platform linux, python 3.11.7-final-0 -----------
Coverage HTML written to dir htmlcov

============================== 23 passed in 4.2[8](https://github.com/filipegalo/trfu/actions/runs/7152602668/job/19478100775#step:7:9)s ==============================
MishaKav commented 11 months ago

looks like your report doesn't have the coverage information. If you can't see the coverage information on terminal, this action can do anything with this. The action works when pytest generate the coverage table in the terminal.

filipegalo commented 11 months ago

looks like your report doesn't have the coverage information. If you can't see the coverage information on terminal, this action can do anything with this. The action works when pytest generate the coverage table in the terminal.

You are right, this was missing: --cov-report=term

MishaKav commented 11 months ago

Seems like --cov-report=term fix the problem. Closing this issue.