Skip to content

Commit bd88a64

Browse files
committed
reference: separate node types to their own section
I think it's helpful to separate the node classes from the other objects, as they have their own unique usage. I've chosen not to alphabetize the order, but to use a logical order instead. Also slightly improve the docstrings.
1 parent 264e7ac commit bd88a64

File tree

4 files changed

+99
-83
lines changed

4 files changed

+99
-83
lines changed

doc/en/reference/reference.rst

Lines changed: 76 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -783,25 +783,17 @@ reporting or interaction with exceptions:
783783
.. autofunction:: pytest_leave_pdb
784784

785785

786-
Objects
787-
-------
788-
789-
Full reference to objects accessible from :ref:`fixtures <fixture>` or :ref:`hooks <hook-reference>`.
790-
791-
792-
CallInfo
793-
~~~~~~~~
794-
795-
.. autoclass:: pytest.CallInfo()
796-
:members:
786+
Collection tree objects
787+
-----------------------
797788

789+
These are the collector and item classes (collectively called "nodes") which
790+
make up the collection tree.
798791

799-
Class
800-
~~~~~
792+
Node
793+
~~~~
801794

802-
.. autoclass:: pytest.Class()
795+
.. autoclass:: _pytest.nodes.Node()
803796
:members:
804-
:show-inheritance:
805797

806798
Collector
807799
~~~~~~~~~
@@ -810,52 +802,52 @@ Collector
810802
:members:
811803
:show-inheritance:
812804

813-
CollectReport
814-
~~~~~~~~~~~~~
805+
Item
806+
~~~~
815807

816-
.. autoclass:: pytest.CollectReport()
808+
.. autoclass:: pytest.Item()
817809
:members:
818810
:show-inheritance:
819-
:inherited-members:
820811

821-
Config
822-
~~~~~~
812+
File
813+
~~~~
823814

824-
.. autoclass:: pytest.Config()
815+
.. autoclass:: pytest.File()
825816
:members:
817+
:show-inheritance:
826818

827-
ExceptionInfo
828-
~~~~~~~~~~~~~
819+
FSCollector
820+
~~~~~~~~~~~
829821

830-
.. autoclass:: pytest.ExceptionInfo()
822+
.. autoclass:: _pytest.nodes.FSCollector()
831823
:members:
824+
:show-inheritance:
832825

826+
Session
827+
~~~~~~~
833828

834-
ExitCode
835-
~~~~~~~~
836-
837-
.. autoclass:: pytest.ExitCode
829+
.. autoclass:: pytest.Session()
838830
:members:
831+
:show-inheritance:
839832

840-
File
841-
~~~~
833+
Package
834+
~~~~~~~
842835

843-
.. autoclass:: pytest.File()
836+
.. autoclass:: pytest.Package()
844837
:members:
845838
:show-inheritance:
846839

840+
Module
841+
~~~~~~
847842

848-
FixtureDef
849-
~~~~~~~~~~
850-
851-
.. autoclass:: _pytest.fixtures.FixtureDef()
843+
.. autoclass:: pytest.Module()
852844
:members:
853845
:show-inheritance:
854846

855-
FSCollector
856-
~~~~~~~~~~~
847+
Class
848+
~~~~~
857849

858-
.. autoclass:: _pytest.nodes.FSCollector()
850+
.. autoclass:: pytest.Class()
859851
:members:
860852
:show-inheritance:
861853

@@ -873,10 +865,52 @@ FunctionDefinition
873865
:members:
874866
:show-inheritance:
875867

876-
Item
877-
~~~~
878868

879-
.. autoclass:: pytest.Item()
869+
Objects
870+
-------
871+
872+
Objects accessible from :ref:`fixtures <fixture>` or :ref:`hooks <hook-reference>`
873+
or importable from ``pytest``.
874+
875+
876+
CallInfo
877+
~~~~~~~~
878+
879+
.. autoclass:: pytest.CallInfo()
880+
:members:
881+
882+
CollectReport
883+
~~~~~~~~~~~~~
884+
885+
.. autoclass:: pytest.CollectReport()
886+
:members:
887+
:show-inheritance:
888+
:inherited-members:
889+
890+
Config
891+
~~~~~~
892+
893+
.. autoclass:: pytest.Config()
894+
:members:
895+
896+
ExceptionInfo
897+
~~~~~~~~~~~~~
898+
899+
.. autoclass:: pytest.ExceptionInfo()
900+
:members:
901+
902+
903+
ExitCode
904+
~~~~~~~~
905+
906+
.. autoclass:: pytest.ExitCode
907+
:members:
908+
909+
910+
FixtureDef
911+
~~~~~~~~~~
912+
913+
.. autoclass:: _pytest.fixtures.FixtureDef()
880914
:members:
881915
:show-inheritance:
882916

@@ -907,31 +941,12 @@ Metafunc
907941
.. autoclass:: pytest.Metafunc()
908942
:members:
909943

910-
Module
911-
~~~~~~
912-
913-
.. autoclass:: pytest.Module()
914-
:members:
915-
:show-inheritance:
916-
917-
Node
918-
~~~~
919-
920-
.. autoclass:: _pytest.nodes.Node()
921-
:members:
922-
923944
Parser
924945
~~~~~~
925946

926947
.. autoclass:: pytest.Parser()
927948
:members:
928949

929-
Package
930-
~~~~~~~
931-
932-
.. autoclass:: pytest.Package()
933-
:members:
934-
935950
OptionGroup
936951
~~~~~~~~~~~
937952

@@ -947,13 +962,6 @@ PytestPluginManager
947962
:inherited-members:
948963
:show-inheritance:
949964

950-
Session
951-
~~~~~~~
952-
953-
.. autoclass:: pytest.Session()
954-
:members:
955-
:show-inheritance:
956-
957965
TestReport
958966
~~~~~~~~~~
959967

src/_pytest/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ def __missing__(self, path: Path) -> str:
462462

463463
@final
464464
class Session(nodes.FSCollector):
465+
"""The root of the collection tree.
466+
467+
``Session`` collects the initial paths given as arguments to pytest.
468+
"""
469+
465470
Interrupted = Interrupted
466471
Failed = Failed
467472
# Set on the session by runner.pytest_sessionstart.

src/_pytest/nodes.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ def _create(self, *k, **kw):
157157

158158

159159
class Node(metaclass=NodeMeta):
160-
"""Base class for Collector and Item, the components of the test
161-
collection tree.
160+
r"""Base class of :class:`Collector` and :class:`Item`, the components of
161+
the test collection tree.
162162
163-
Collector subclasses have children; Items are leaf nodes.
163+
``Collector``\'s are the internal nodes of the tree, and ``Item``\'s are the
164+
leaf nodes.
164165
"""
165166

166167
# Implemented in the legacypath plugin.
@@ -525,15 +526,17 @@ def get_fslocation_from_item(node: "Node") -> Tuple[Union[str, Path], Optional[i
525526

526527

527528
class Collector(Node):
528-
"""Collector instances create children through collect() and thus
529-
iteratively build a tree."""
529+
"""Base class of all collectors.
530+
531+
Collector create children through `collect()` and thus iteratively build
532+
the collection tree.
533+
"""
530534

531535
class CollectError(Exception):
532536
"""An error during collection, contains a custom message."""
533537

534538
def collect(self) -> Iterable[Union["Item", "Collector"]]:
535-
"""Return a list of children (items and collectors) for this
536-
collection node."""
539+
"""Collect children (items and collectors) for this collector."""
537540
raise NotImplementedError("abstract")
538541

539542
# TODO: This omits the style= parameter which breaks Liskov Substitution.
@@ -577,6 +580,8 @@ def _check_initialpaths_for_relpath(session: "Session", path: Path) -> Optional[
577580

578581

579582
class FSCollector(Collector):
583+
"""Base class for filesystem collectors."""
584+
580585
def __init__(
581586
self,
582587
fspath: Optional[LEGACY_PATH] = None,
@@ -660,7 +665,7 @@ class File(FSCollector):
660665

661666

662667
class Item(Node):
663-
"""A basic test invocation item.
668+
"""Base class of all test invocation items.
664669
665670
Note that for a single function there might be multiple test invocation items.
666671
"""

src/_pytest/python.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def _genfunctions(self, name: str, funcobj) -> Iterator["Function"]:
522522

523523

524524
class Module(nodes.File, PyCollector):
525-
"""Collector for test classes and functions."""
525+
"""Collector for test classes and functions in a Python module."""
526526

527527
def _getobj(self):
528528
return self._importtestmodule()
@@ -791,7 +791,7 @@ def _get_first_non_fixture_func(obj: object, names: Iterable[str]) -> Optional[o
791791

792792

793793
class Class(PyCollector):
794-
"""Collector for test methods."""
794+
"""Collector for test methods (and nested classes) in a Python class."""
795795

796796
@classmethod
797797
def from_parent(cls, parent, *, name, obj=None, **kw):
@@ -1676,7 +1676,7 @@ def write_docstring(tw: TerminalWriter, doc: str, indent: str = " ") -> None:
16761676

16771677

16781678
class Function(PyobjMixin, nodes.Item):
1679-
"""An Item responsible for setting up and executing a Python test function.
1679+
"""Item responsible for setting up and executing a Python test function.
16801680
16811681
:param name:
16821682
The full function name, including any decorations like those
@@ -1833,10 +1833,8 @@ def repr_failure( # type: ignore[override]
18331833

18341834

18351835
class FunctionDefinition(Function):
1836-
"""
1837-
This class is a step gap solution until we evolve to have actual function definition nodes
1838-
and manage to get rid of ``metafunc``.
1839-
"""
1836+
"""This class is a stop gap solution until we evolve to have actual function
1837+
definition nodes and manage to get rid of ``metafunc``."""
18401838

18411839
def runtest(self) -> None:
18421840
raise RuntimeError("function definitions are not supposed to be run as tests")

0 commit comments

Comments
 (0)