Search code examples
pythondjangounit-testingpytestabc

Coverage expects a test case for an @abstractmethod


As you can see in the picture below, coverage wants me to write a test case for the method inside the abc. But I dont know how to do it, I mean as far as I can see there is nothing to test.

enter image description here

Code:

from abc import ABC, abstractmethod


class BaseVPS(ABC):
    @abstractmethod
    def create_server(self):
        ...

Solution

  • Since testing something like an @abstractmethod is unnecessary, we can add this configuration file to the root of our project to add exclusions to the coverage.

    pyproject.toml:

    [tool.coverage.report]
    exclude_also = [
        "@(abc\\.)?abstractmethod",
        ]