Problem with include and omit filename patterns that start with asterisk

markdoliner avatarmarkdoliner created an issue

Using the coverage api, say I pass in include or omit parameters that look like this:

cov.html_report(
    directory='/home/mark/someproject',
    include=['*.py']
)

or

cov.html_report(
    directory='/home/mark/someproject',
    omit=['*.js']
)

When this runs, the include and omit patterns get munged into an absolute path which is relative to the current working directory. This happens because the find_code_units() function in report.py calls file_locator.abs_file() for each pattern.

This is fine if the current working directory is /home/mark/someproject/. But it causes problems if the current working directory is /home/mark/someproject/tests/. In this case the pattern is munged to '/home/mark/someproject/tests/*.py', which won't match the source code for my project.

I can work around this by simply adding a slash to the beginning of my patterns. This changes the pattern to an absolute path and file_locator.abs_file() will not alter it.

I don't think I understand the reason for calling file_locator.abs_file() on the patterns in this case... maybe we could just remove that?

Comments (3)

  1. divius

    Hi guys!

    I've found a problem that looks similar. For me omit="*..." always produce an empty report. E.g.:

    coverage.report(include="*/pycom/*", omit="*banana!",
                    ignore_errors=False, show_missing=True)
    

    produces empty report while

    coverage.report(include="*/pycom/*",
                    ignore_errors=False, show_missing=True)
    

    produces correct one.

    Tested on 3.5.1 and 3.4.

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.