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]
)
| 136 | |
| 137 | |
| 138 | def 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 | |
| 163 | def get_scope_node(node: nodes.Node, scope: Scope) -> nodes.Node | None: |
no test coverage detected