MishaKav / pytest-coverage-comment

Comments a pull request with the pytest code coverage badge and full report

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Error on generating summary report. Cannot read properties of undefined (reading 'testsuite')

sohilnandu opened this issue · comments

commented

When using this workflow, both the .xml and the .txt file seem to be read fine, but there is an error when generating the summary report:

Generating coverage report
File read successfully "/home/runner/work/origami-flask/origami-flask/./backend/coverage.xml"
Error: Error on generating summary report. Cannot read properties of undefined (reading 'testsuite')
File read successfully "/home/runner/work/origami-flask/origami-flask/./backend/pytest-coverage.txt"
Generating coverage report

What is causing this error?

Can you please share with me one of the files, so I can debug it?

commented

@MishaKav Sure. I was not certain I wanted to post the files here so I have emailed them to you.
Thanks for helping!

Thanks for sharing, I rerun it several times and successfully generated all kinds of reports.
From the error message that you share, I assume that you provide the coverage.xml to the wrong parameter, it should be pytest-xml-coverage-path: ./coverage.xml and not junitxml-path: ./coverage.xml (because the word testsuite relevant only for junit format).

Can you check it please ?

commented

Thanks @MishaKav
I made the change you suggested and it removed the error when generating the summary report. However, I still do not see the summary report output in the comment. I tried to echo the summary report and got this error message:

Run echo "Coverage Percantage - {"name":"TOTAL","stmts":788,"miss":302,"cover":"61%"}"
Coverage Percantage - {name:TOTAL,stmts:788,miss:302,cover:61%}
Coverage Color - yellow
/home/runner/work/_temp/7b5abaae-4fb1-470a-b7db-67e915eefaa1.sh: line 3: syntax error near unexpected token `<'
Error: Process completed with exit code 2.

Also, the coverage report in the commit comment now shows every value in the "Stmts" column as 0. Before the change you suggested, it had the correct values.
image

  1. when you try to get a coverage report from coverage.xml the Stmts will be always 0 because they are not provided in xml report. You can generate the same report from pytest-coverage.txt that always has Stmts

  2. when you try to print the output it yields that has unsupported characters because it HTML characters. If you want to output it, I can suggest you this, it will print the output in summary of the action

- name: Add Summary
  uses: actions/github-script@v6
  with:
    script: |
      core.summary.addRaw(${{ steps.coverageComment.outputs.summaryReport }}).write()

image

commented
  1. Ok, that makes sense. I am able to see Stmts when using pytest-coverage.txt
  2. I was able to use your method to output the summary HTML and verify that it is actually there.
  3. For some reason, the summary is not being added to the commit comments. Below is all the info for my setup. I think there is something very simple that I am doing wrong.
- name: Run unit tests
  working-directory: ./backend
  run: |
    pipenv run pytest --cov --cov-report "xml:coverage.xml" --cov-report=term-missing:skip-covered tests/ | tee pytest-coverage.txt

- name: Pytest coverage comment
  id: coverageComment
  uses: MishaKav/pytest-coverage-comment@main
  with:
    pytest-coverage-path: ./backend/pytest-coverage.txt
    default-branch: master
    coverage-path-prefix: backend/  

- name: Add Summary
  uses: actions/github-script@v6
  with:
    script: |
      core.summary.addRaw(${{ steps.coverageComment.outputs.summaryReport }}).write()

The above workflow produced this commit comment without the summary:
image

Any help with debugging this is greatly appreciated 🙏🏽

From what I see the comment was generated exactly as you provide the inputs.
When you talk about summary, which summary do you mean?

commented

I thought there should be a summary below the Coverage Report like in this screenshot:
image

for this report you should provide junitxml-path: ./pytest.xml.
You can generate it by pytest --junitxml=pytest.xml

commented

Thank you very much @MishaKav. That did it. Appreciate your help!