Problem with include and omit filename patterns that start with asterisk · Issue #163 · nedbat/coveragepy (original) (raw)

Originally reported by Mark Doliner (Bitbucket: markdoliner, GitHub: markdoliner)


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?