Option to use relative file paths in .coverage file

Issue #597 closed
Andrei Fokau created an issue

I test my project in a Docker container and then examine covered lines in PyCharm on my host machine. Currently PyCharm can only load XML reports in Cobertura format and does actually have an issue due to expecting absolute file paths there. JetBrains guys are going to fix the issue I believe, but I wonder if we can add an option in coverage.py to produce .coverage file with relative paths so that one could run tests in a Docker container and then produce report on host machine? If .coverage contains relative paths, PyCharm would hopefully be able to load them directly without producing intermediate XML files.

Comments (7)

  1. Ned Batchelder repo owner

    This sounds like something the [paths] section of the .coveragerc was meant to solve.

  2. Andrei Fokau reporter

    I am not sure how to use it. I have now .coverage file with paths starting with /app/myproj/.... I added [paths] to my config file:

    source = myproj
    branch = True
    omit =
    fail_under = 67
    skip_covered = True
    show_missing = True
    # Regex expressions for lines excluded from report
    exclude_lines =
        pragma: no cover
        if __name__ == .__main__.:
    source =

    coverage report still shows NoSource errors.

  3. Ned Batchelder repo owner

    Make sure this is right: "The first value must be an actual file path on the machine where the reporting will happen, so that source code can be found." Also, this is used when combining data files. Do you use "coverage combine"?

  4. Andrei Fokau reporter

    @ned No, I don't use combine. I'll try to debug it later. It seems that absolute/relative paths issue can be related also to Cobertura issue since the paths are relative there. If you don't plan to use absolute paths in Cobertura XML, then I guess .coverage could also use relative paths, or I am wrong here?

  5. Log in to comment