Skip to content

Commit

Permalink
fix: correct .coveragerc omitted files globs (#333)
Browse files Browse the repository at this point in the history
Coverage.py file patterns only matches entire directories if the file
pattern ends with a slash and asterisk ("/*").

In addition to the rule above, Coverage.py file patterns that start with
a wildcard character only matches entire directories if the file pattern
starts with an asterisk and slash ("*/").

Example:

    % python
    Python 3.8.11 (default, Aug 23 2021, 18:14:59)
    >>> import coverage
    >>> coverage.version_info
    (7, 2, 3, 'final', 0)
    >>> from coverage.files import GlobMatcher
    >>> GlobMatcher(["*migrations*"], "omit").match("/dir/project/migrations/0001_initial.py")
    False
    >>> GlobMatcher(["*/migrations/*"], "omit").match("/dir/project/migrations/0001_initial.py")
    True
    >>> GlobMatcher(["/dir/project/settings*"], "omit").match("/dir/project/settings/base.py")
    False
    >>> GlobMatcher(["/dir/project/settings/*"], "omit").match("/dir/project/settings/base.py")
    True
    >>> GlobMatcher(["*admin.py"], "omit").match("/dir/project/app/app_name/admin.py")
    True

See:

* [InOrOut.check_include_omit_etc()](https://github.com/nedbat/coveragepy/blob/cf3602ffa7396d8f784c1a1e814ff24c6c31f793/coverage/inorout.py#L444)
* [GlobMatcher in self.omit](https://github.com/nedbat/coveragepy/blob/cf3602ffa7396d8f784c1a1e814ff24c6c31f793/coverage/inorout.py#L253)
* [Definition of self.omit](https://github.com/nedbat/coveragepy/blob/cf3602ffa7396d8f784c1a1e814ff24c6c31f793/coverage/inorout.py#L205)
* [Coverage.py glob documentation](https://coverage.readthedocs.io/en/7.2.5/source.html#file-patterns)
  • Loading branch information
pshiu authored May 8, 2023
1 parent 7d7b9bc commit 42d47f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Change Log
This file loosely adheres to the structure of https://keepachangelog.com/,
but in reStructuredText instead of Markdown.
2023-05-04
**********

Fixed
=====

- Correct .coveragerc ``omit`` file paths to properly specify directories.

2023-05-03
**********

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ branch = True
data_file = .coverage
source={{cookiecutter.app_name}}
omit =
test_settings
*migrations*
test_settings.py
*/migrations/*
*admin.py
*static*
*templates*
*/static/*
*/templates/*
10 changes: 5 additions & 5 deletions cookiecutter-django-ida/{{cookiecutter.repo_name}}/.coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ branch = True
data_file = .coverage
source={{cookiecutter.project_name}}
omit =
{{cookiecutter.project_name}}/settings*
{{cookiecutter.project_name}}/conf*
{{cookiecutter.project_name}}/settings/*
{{cookiecutter.project_name}}/conf/*
*wsgi.py
*migrations*
*/migrations/*
*admin.py
*static*
*templates*
*/static/*
*/templates/*

0 comments on commit 42d47f7

Please sign in to comment.