_pytest.nodes module

_splitnode(nodeid)[source]

Split a nodeid into constituent ‘parts’.

Node IDs are strings, and can be things like:

‘’ ‘testing/code’ ‘testing/code/test_excinfo.py’ ‘testing/code/test_excinfo.py::TestFormattedExcinfo’

Return values are lists e.g.

[] [‘testing’, ‘code’] [‘testing’, ‘code’, ‘test_excinfo.py’] [‘testing’, ‘code’, ‘test_excinfo.py’, ‘TestFormattedExcinfo’]

ischildnode(baseid, nodeid)[source]

Return True if the nodeid is a child node of the baseid.

E.g. ‘foo/bar::Baz’ is a child of ‘foo’, ‘foo/bar’ and ‘foo/bar::Baz’, but not of ‘foo/blorp’

class NodeMeta[source]

Bases: type

_create(*k, **kw)[source]
class Node(*k, **kw)[source]

Bases: object

base class for Collector and Item the test collection tree. Collector subclasses have children, Items are terminal nodes.

name

a unique name within the scope of the parent node

parent

the parent collector node.

fspath: py.path.local

filesystem path where this node was collected from (can be None)

keywords

keywords/markers collected from all scopes

own_markers: List[Mark]

the marker objects belonging to this node

extra_keyword_matches: Set[str]

allow adding of extra keywords to use for matching

classmethod from_parent(parent: _pytest.nodes.Node, **kw)[source]

Public Constructor for Nodes

This indirection got introduced in order to enable removing the fragile logic from the node constructors.

Subclasses can use super().from_parent(...) when overriding the construction

Parameters

parent – the parent node of this test Node

ihook

fspath sensitive hook proxy used to call pytest hooks

warn(warning)[source]

Issue a warning for this item.

Warnings will be displayed after the test session, unless explicitly suppressed

Parameters

warning (Warning) – the warning instance to issue. Must be a subclass of PytestWarning.

Raises

ValueError – if warning instance is not a subclass of PytestWarning.

Example usage:

node.warn(PytestWarning("some message"))
nodeid

a ::-separated string denoting its collection tree address.

setup()[source]
teardown()[source]
listchain() → List[_pytest.nodes.Node][source]

return list of all parent collectors up to self, starting from root of collection tree.

add_marker(marker: Union[str, _pytest.mark.structures.MarkDecorator], append: bool = True)None[source]

dynamically add a marker object to the node.

Parameters

marker (str or pytest.mark.* object) – append=True whether to append the marker, if False insert at position 0.

iter_markers(name=None)[source]
Parameters

name – if given, filter the results by the name attribute

iterate over all markers of the node

for ... in iter_markers_with_node(name=None)[source]
Parameters

name – if given, filter the results by the name attribute

iterate over all markers of the node returns sequence of tuples (node, mark)

get_closest_marker(name, default=None)[source]

return the first marker matching the name, from closest (for example function) to farther level (for example module level).

Parameters
  • default – fallback return value of no marker was found

  • name – name to filter by

listextrakeywords()[source]

Return a set of all extra keywords in self and any parents.

listnames()[source]
addfinalizer(fin)[source]

register a function to be called when this node is finalized.

This method can only be called when this node is active in a setup chain, for example during self.setup().

getparent(cls)[source]

get the next parent node (including ourself) which is an instance of the given class

_prunetraceback(excinfo)[source]
_repr_failure_py(excinfo: _pytest._code.code.ExceptionInfo[Union[_pytest.outcomes.Failed, _pytest.fixtures.FixtureLookupError]], default_style: _TracebackStyle = None) → Union[str, _pytest._code.code.ReprExceptionInfo, _pytest._code.code.ExceptionChainRepr, _pytest.fixtures.FixtureLookupErrorRepr][source]
repr_failure(excinfo, style=None) → Union[str, _pytest._code.code.ReprExceptionInfo, _pytest._code.code.ExceptionChainRepr, _pytest.fixtures.FixtureLookupErrorRepr][source]
get_fslocation_from_item(item: _pytest.nodes.Item) → Tuple[Union[str, py._path.local.LocalPath], Optional[int]][source]

Tries to extract the actual location from an item, depending on available attributes:

  • “fslocation”: a pair (path, lineno)

  • “obj”: a Python object that the item wraps.

  • “fspath”: just a path

Return type

a tuple of (str|LocalPath, int) with filename and line number.

class Collector(*k, **kw)[source]

Bases: _pytest.nodes.Node

Collector instances create children through collect() and thus iteratively build a tree.

exception CollectError[source]

Bases: Exception

an error during collection, contains a custom message.

collect()[source]

returns a list of children (items and collectors) for this collection node.

repr_failure(excinfo)[source]

represent a collection failure.

_prunetraceback(excinfo)[source]
class FSHookProxy(fspath: py._path.local.LocalPath, pm: _pytest.config.PytestPluginManager, remove_mods)[source]

Bases: object

class FSCollector(*k, **kw)[source]

Bases: _pytest.nodes.Collector

classmethod from_parent(parent, *, fspath)[source]

The public constructor

_gethookproxy(fspath: py._path.local.LocalPath)[source]
_is_ignored(ihook, path: py._path.local.LocalPath)bool[source]

Wrap pytest_ignore_collect to support tuple return value.

_recurse(dirpath: py._path.local.LocalPath)bool[source]
_collectfile(path, handle_dupes=True)[source]
class File(*k, **kw)[source]

Bases: _pytest.nodes.FSCollector

base class for collecting tests from a file.

class Item(*k, **kw)[source]

Bases: _pytest.nodes.Node

a basic test invocation item. Note that for a single function there might be multiple test invocation items.

nextitem = None
user_properties: List[Tuple[str, Any]]

user properties is a list of tuples (name, value) that holds user defined properties for this test.

runtest()None[source]
add_report_section(when: str, key: str, content: str)None[source]

Adds a new report section, similar to what’s done internally to add stdout and stderr captured output:

item.add_report_section("call", "stdout", "report section contents")
Parameters
  • when (str) – One of the possible capture states, "setup", "call", "teardown".

  • key (str) – Name of the section, can be customized at will. Pytest uses "stdout" and "stderr" internally.

  • content (str) – The full contents as a string.

reportinfo() → Tuple[Union[py._path.local.LocalPath, str], Optional[int], str][source]
location