1+ import abc
12import os
23import warnings
34from functools import cached_property
@@ -121,7 +122,7 @@ def _imply_path(
121122_NodeType = TypeVar ("_NodeType" , bound = "Node" )
122123
123124
124- class NodeMeta (type ):
125+ class NodeMeta (abc . ABCMeta ):
125126 """Metaclass used by :class:`Node` to enforce that direct construction raises
126127 :class:`Failed`.
127128
@@ -165,7 +166,7 @@ def _create(self, *k, **kw):
165166 return super ().__call__ (* k , ** known_kw )
166167
167168
168- class Node (metaclass = NodeMeta ):
169+ class Node (abc . ABC , metaclass = NodeMeta ):
169170 r"""Base class of :class:`Collector` and :class:`Item`, the components of
170171 the test collection tree.
171172
@@ -534,7 +535,7 @@ def get_fslocation_from_item(node: "Node") -> Tuple[Union[str, Path], Optional[i
534535 return getattr (node , "fspath" , "unknown location" ), - 1
535536
536537
537- class Collector (Node ):
538+ class Collector (Node , abc . ABC ):
538539 """Base class of all collectors.
539540
540541 Collector create children through `collect()` and thus iteratively build
@@ -544,6 +545,7 @@ class Collector(Node):
544545 class CollectError (Exception ):
545546 """An error during collection, contains a custom message."""
546547
548+ @abc .abstractmethod
547549 def collect (self ) -> Iterable [Union ["Item" , "Collector" ]]:
548550 """Collect children (items and collectors) for this collector."""
549551 raise NotImplementedError ("abstract" )
@@ -588,7 +590,7 @@ def _check_initialpaths_for_relpath(session: "Session", path: Path) -> Optional[
588590 return None
589591
590592
591- class FSCollector (Collector ):
593+ class FSCollector (Collector , abc . ABC ):
592594 """Base class for filesystem collectors."""
593595
594596 def __init__ (
@@ -666,14 +668,14 @@ def isinitpath(self, path: Union[str, "os.PathLike[str]"]) -> bool:
666668 return self .session .isinitpath (path )
667669
668670
669- class File (FSCollector ):
671+ class File (FSCollector , abc . ABC ):
670672 """Base class for collecting tests from a file.
671673
672674 :ref:`non-python tests`.
673675 """
674676
675677
676- class Item (Node ):
678+ class Item (Node , abc . ABC ):
677679 """Base class of all test invocation items.
678680
679681 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:
739741 PytestWarning ,
740742 )
741743
744+ @abc .abstractmethod
742745 def runtest (self ) -> None :
743746 """Run the test case for this item.
744747
0 commit comments