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. 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:

    [coverage:run]
    source = myproj
    branch = True
    omit =
        */migrations/*
    
    [coverage:report]
    fail_under = 67
    skip_covered = True
    show_missing = True
    
    # Regex expressions for lines excluded from report
    exclude_lines =
        pragma: no cover
        if __name__ == .__main__.:
    
    [coverage:paths]
    source =
        myproj
        /app/myproj
        /Users/andrei/myproj
    

    coverage report still shows NoSource errors.

  2. 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"?

  3. Andrei Fokau reporter

    @Ned Batchelder 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?

  4. Log in to comment