-
-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore ABC abstract methods #1131
Comments
Will it work for you to update your
|
No, but the following might will:
I'll check it. Even though it is a solid solution, I think that this case is general enough to be handled directly with a flag or a specific configuration. |
You don't want to add "...", that's a regex that matches almost every line of your code (se #1042). Try the setting I suggested, I think it will work for you. I'm reluctant to add hard-coded options for language features, because different people approach them differently, and the language changes over time. |
I don't know if it would be helpful to add to the default excluded lines pattern? |
Another way to do it might be to automatically ignore "trivial" function bodies like mypy already does. "Trivial" function bodies, according to mypy, have a single |
Maybe we could add something to the docs that suggest these sorts of regexes? I think regexes in the configuration file are powerful enough for what people need to do. |
#894 is blocking that. |
@ktbarrett can you show me some of the code you are working with, and what you would like to do? |
I'd like to ignore the bodies of abstract functions. @abstractmethod
def method(self, arg: int) -> str:
"""docstring with code examples in it"""
pass Adding just try:
return may_fail()
except Exception:
pass
return NotImplemented I thought for a second I could write a regex that could detect such cases, but I now realize that isn't really reasonable/possible. I've adjusted my current strategy to:
|
There's something people are missing in this discussion: since coverage.py v4.1, if you exclude a decorator, it excludes the entire decorated function. So the best exclude line here would be:
Once you do that, the entire abstract method is excluded from coverage, no matter what statements it contains. BTW, this is also being discussed in pytest-cov: pytest-dev/pytest-cov#428 |
Also, I see that this behavior of excluding a decorator isn't mentioned in the docs! I will fix that. |
There is the possibility that abstractmethods could have behavior in them that is intended to be run with a |
Also doesn't cover setters of If someone were interested I would add the following to your
|
I've added to the docs in c6d9eb9. |
…is not implemented or abstract See e.g. nedbat/coveragepy#1131
Is your feature request related to a problem? Please describe.
Sometimes you want to create an abstract class with abstract methods that will be overridden by other subclasses. For example:
Pay attention that while
Bar.a
content should be covered by test, the content ofFoo.a
should not since there is no actual gain in covering it with a test.Describe the solution you'd like
Coverage should ignore abstract methods by default and should not require coverage for them.
Describe alternatives you've considered
If you think that sometimes abstract methods should be covered, maybe we can make this ability toggleable by a flag (
--ignore-abstract
) for example.Additional context
This API is available only in Python 3, therefore we should make sure we disable it in Python 2.
The text was updated successfully, but these errors were encountered: