1
+ import abc
1
2
import os
2
3
import warnings
3
4
from functools import cached_property
@@ -121,7 +122,7 @@ def _imply_path(
121
122
_NodeType = TypeVar ("_NodeType" , bound = "Node" )
122
123
123
124
124
- class NodeMeta (type ):
125
+ class NodeMeta (abc . ABCMeta ):
125
126
"""Metaclass used by :class:`Node` to enforce that direct construction raises
126
127
:class:`Failed`.
127
128
@@ -165,7 +166,7 @@ def _create(self, *k, **kw):
165
166
return super ().__call__ (* k , ** known_kw )
166
167
167
168
168
- class Node (metaclass = NodeMeta ):
169
+ class Node (abc . ABC , metaclass = NodeMeta ):
169
170
r"""Base class of :class:`Collector` and :class:`Item`, the components of
170
171
the test collection tree.
171
172
@@ -534,7 +535,7 @@ def get_fslocation_from_item(node: "Node") -> Tuple[Union[str, Path], Optional[i
534
535
return getattr (node , "fspath" , "unknown location" ), - 1
535
536
536
537
537
- class Collector (Node ):
538
+ class Collector (Node , abc . ABC ):
538
539
"""Base class of all collectors.
539
540
540
541
Collector create children through `collect()` and thus iteratively build
@@ -544,6 +545,7 @@ class Collector(Node):
544
545
class CollectError (Exception ):
545
546
"""An error during collection, contains a custom message."""
546
547
548
+ @abc .abstractmethod
547
549
def collect (self ) -> Iterable [Union ["Item" , "Collector" ]]:
548
550
"""Collect children (items and collectors) for this collector."""
549
551
raise NotImplementedError ("abstract" )
@@ -588,7 +590,7 @@ def _check_initialpaths_for_relpath(session: "Session", path: Path) -> Optional[
588
590
return None
589
591
590
592
591
- class FSCollector (Collector ):
593
+ class FSCollector (Collector , abc . ABC ):
592
594
"""Base class for filesystem collectors."""
593
595
594
596
def __init__ (
@@ -666,14 +668,14 @@ def isinitpath(self, path: Union[str, "os.PathLike[str]"]) -> bool:
666
668
return self .session .isinitpath (path )
667
669
668
670
669
- class File (FSCollector ):
671
+ class File (FSCollector , abc . ABC ):
670
672
"""Base class for collecting tests from a file.
671
673
672
674
:ref:`non-python tests`.
673
675
"""
674
676
675
677
676
- class Item (Node ):
678
+ class Item (Node , abc . ABC ):
677
679
"""Base class of all test invocation items.
678
680
679
681
Note that for a single function there might be multiple test invocation items.
@@ -739,6 +741,7 @@ def _check_item_and_collector_diamond_inheritance(self) -> None:
739
741
PytestWarning ,
740
742
)
741
743
744
+ @abc .abstractmethod
742
745
def runtest (self ) -> None :
743
746
"""Run the test case for this item.
744
747
0 commit comments