MishaKav / pytest-coverage-comment

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

Links to files with dunder/double underscores are broken #118

Closed icj217 closed 1 year ago

icj217 commented 1 year ago

I noticed in testing out this action that links don't seem to work properly to files that contain dunders, e.g. __init__.py. See below for details.

My XML report shows the filenames correctly:

<?xml version="1.0" ?>
<coverage version="6.4.4" timestamp="1677247940858" lines-valid="4" lines-covered="3" line-rate="0.75" branches-valid="0" branches-covered="0" branch-rate="1" complexity="0">
    <!-- Generated by coverage.py: https://coverage.readthedocs.io -->
    <!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
    <sources>
        <source>REDACTED</source>
    </sources>
    <packages>
        <package name="src.my_cool_lib" line-rate="0.75" branch-rate="1" complexity="0">
            <classes>
                <class name="__init__.py" filename="src/my_cool_lib/__init__.py" complexity="0" line-rate="1" branch-rate="1">
                    <methods/>
                    <lines>
                        <line number="3" hits="1"/>
                    </lines>
                </class>
                <class name="__main__.py" filename="src/my_cool_lib/__main__.py" complexity="0" line-rate="0" branch-rate="1">
                    <methods/>
                    <lines>
                        <line number="2" hits="0"/>
                    </lines>
                </class>
                <class name="example.py" filename="src/my_cool_lib/example.py" complexity="0" line-rate="1" branch-rate="1">
                    <methods/>
                    <lines>
                        <line number="4" hits="1"/>
                        <line number="11" hits="1"/>
                    </lines>
                </class>
            </classes>
        </package>
    </packages>
</coverage>

And here's my action configuration:

- uses: MishaKav/pytest-coverage-comment@main
  with:
    title: Unit Test Coverage Report
    badge-title: Unit Test Coverage
    pytest-xml-coverage-path: reports/unittest-cov.xml
    junitxml-path: reports/unittest.xml

The comment is generated properly:

Screen Shot 2023-02-24 at 9 26 09 AM

But the links to the __init__.py and __main__.py are the following:

https://github.com/myorg/myrepo/blob/60330af0c8dd07545e84d15ae15405b6c408e969/src/my_cool_lib//_/_init/_/_.py
https://github.com/myorg/myrepo/blob/60330af0c8dd07545e84d15ae15405b6c408e969/src/my_cool_lib//_/_main/_/_.py

Oddly enough, the link to line 2 of __main__.py is correct:

https://github.com/myorg/myrepo/blob/60330af0c8dd07545e84d15ae15405b6c408e969/src/my_cool_lib/__main__.py#L2
MishaKav commented 1 year ago

Thanks for the detailed example, I will check the issue and provide a fix soon.

MishaKav commented 1 year ago

I fix this bug, you can use:

- name: Pytest Coverage Comment
  uses: MishaKav/pytest-coverage-comment@main

or use a specific version

- name: Pytest Coverage Comment
  uses: MishaKav/pytest-coverage-comment@v1.1.46