MCPcopy
hub / github.com/pytest-dev/pytest / is_visibility_more_specific

Function is_visibility_more_specific

src/_pytest/fixtures.py:138–160  ·  src/_pytest/fixtures.py::is_visibility_more_specific

Return whether the visibility of ``candidate`` is strictly more specific than that of ``other``, i.e. ``candidate`` is defined on a strict descendant in the collection tree of where ``other`` is defined.

(
    candidate: FixtureDef[Any], other: FixtureDef[Any]
)

Source from the content-addressed store, hash-verified

136
137
138def is_visibility_more_specific(
139 candidate: FixtureDef[Any], other: FixtureDef[Any]
140) -> bool:
141 class="st">"""Return whether the visibility of ``candidate`` is strictly more specific
142 than that of ``other``, i.e. ``candidate`` is defined on a strict descendant
143 in the collection tree of where ``other`` is defined.class="st">"""
144 if candidate.node is None or other.node is None:
145 class="cm"># Fallback for fixtures registered with a string nodeid (deprecated).
146 class="cm"># In this case compare baseids, which are nodeid prefixes.
147 class="cm"># This branch can be removed once baseid deprecation is done (pytest 10).
148 if candidate.baseid == other.baseid:
149 return False
150 if other.baseid == class="st">"":
151 return True
152 class="cm"># `candidate.baseid` must continue with a node separator for it to be a
153 class="cm"># true descendant.
154 return candidate.baseid.startswith(other.baseid) and candidate.baseid[
155 len(other.baseid)
156 ] in (class="st">"/", class="st">":")
157
158 return (
159 candidate.node is not other.node and other.node in candidate.node.iter_parents()
160 )
161
162
163def get_scope_node(node: nodes.Node, scope: Scope) -> nodes.Node | None:

Callers 1

_register_fixtureMethod · 0.85

Calls 1

iter_parentsMethod · 0.80

Tested by

no test coverage detected