Skip to content

Add code coverage - #504

Closed
Morgan-Sell wants to merge 4 commits into
feature-engine:mainfrom
Morgan-Sell:code_cvrg
Closed

Add code coverage#504
Morgan-Sell wants to merge 4 commits into
feature-engine:mainfrom
Morgan-Sell:code_cvrg

Conversation

@Morgan-Sell

Copy link
Copy Markdown
Collaborator

Code coverage will allow us to measure how much of the feature-engine source code is tested.

Closes #323.

Notes from #323:

At the moment, we have no visibility of test coverage. I would like to include this in the package.

Here some useful links I gathered:

https://gist.github.com/dnozay/5b9b818ff0dc857d1358

https://pytest-cov.readthedocs.io/en/latest/tox.html

https://coverage.readthedocs.io/en/6.1.1/config.html

Also check imbalanced-learn package, they have some code to run coverage.

@Morgan-Sell

Copy link
Copy Markdown
Collaborator Author

hola @solegalli,

I created the .coveragerc file.

Two questions:

  1. What am I missing from omit and excluded_lines? I suspect there are other files in which unit tests do not apply.
  2. Is there anywhere in the source code where we should add # pragma: no cover so the code is excluded from the code-coverage calculations?

@solegalli

Copy link
Copy Markdown
Collaborator

hi @Morgan-Sell

to be honest I have not used code coverage before, so I need to do some research to answer those questions. In short, I don't know :_(

@Morgan-Sell

Copy link
Copy Markdown
Collaborator Author

Hi @solegalli,

For our current needs, I believe the two main sections are omit and excluded_lines. These are the definitions and examples from coverage documentation:

  1. omit (multi-string): a list of file name patterns, the files to leave out of measurement or reporting.
[run]
omit =
    # omit anything in a .local directory anywhere
    */.local/*
    # omit everything in /usr
    /usr/*
    # omit this single file
    utils/tirefire.py
  1. exclude_lines (multi-string): a list of regular expressions. Any line of your source code containing a match for one of these regexes is excluded from being reported as missing... If you use this option, you are replacing all the exclude regexes, so you’ll need to also supply the “pragma: no cover” regex if you still want to use it.

You can exclude lines introducing blocks, and the entire block is excluded. If you exclude a def line or decorator line, the entire function is excluded.

Be careful when writing this setting: the values are regular expressions that only have to match a portion of the line. For example, if you write ..., you’ll exclude any line with three or more of any character. If you write pass, you’ll also exclude the line my_pass="foo", and so on.

[report]
exclude_lines =
    pragma: no cover
    def __repr__
    if self.debug:
    if settings.DEBUG
    raise AssertionError
    raise NotImplementedError
    if 0:
    if __name__ == .__main__.:
    class .*\bProtocol\):
    @(abc\.)?abstractmethod

Here's imbalanced-learn .coveragerc. With imbalanced-learn, I think using source and include is redundant.

@solegalli solegalli mentioned this pull request Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

include code coverage

2 participants