Skip to content

Commit b02de96

Browse files
committed
test(refactor): abstract method compatible with both pytest and mypy
Using Protocol as a base class introduces a __init__ method, which pytest does not like. This way keeps both tools happy.
1 parent ada3ade commit b02de96

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

metacov.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ exclude_lines =
4343
#
4444
pragma: nested
4545

46+
# Abstract methods
47+
raise NotImplementedError
48+
4649
# Lines that are only executed when we are debugging coverage.py.
4750
def __repr__
4851
pragma: debugging

tests/test_api.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import sys
1616
import textwrap
1717

18-
from typing import cast, Callable, Dict, Iterable, List, Optional, Protocol, Set
18+
from typing import cast, Callable, Dict, Iterable, List, Optional, Set
1919

2020
import pytest
2121

@@ -814,19 +814,14 @@ def test_bug_572(self) -> None:
814814
cov.report()
815815

816816

817-
class CoverageUsePkgs(Protocol):
818-
"""A number of test classes have the same helper method."""
819-
def coverage_usepkgs(
820-
self,
821-
**kwargs: TCovKwargs,
822-
) -> Iterable[str]:
823-
"""Run coverage on usepkgs, return a line summary. kwargs are for Coverage(**kwargs)."""
824-
return ""
825-
826-
827-
class IncludeOmitTestsMixin(CoverageUsePkgs, UsingModulesMixin, CoverageTest):
817+
class IncludeOmitTestsMixin(UsingModulesMixin, CoverageTest):
828818
"""Test methods for coverage methods taking include and omit."""
829819

820+
# An abstract method for subclasses to define, to appease mypy.
821+
def coverage_usepkgs(self, **kwargs_unused: TCovKwargs) -> Iterable[str]:
822+
"""Run coverage on usepkgs, return a line summary. kwargs are for Coverage(**kwargs)."""
823+
raise NotImplementedError()
824+
830825
def filenames_in(self, summary: Iterable[str], filenames: str) -> None:
831826
"""Assert the `filenames` are in the `summary`."""
832827
for filename in filenames.split():

0 commit comments

Comments
 (0)