Statically traverse the fixture dependency closure in DFS order starting from initialnames, yielding all requested fixture names (argnames). Each argname is only yielded once.
(
initialnames: Iterable[str],
*,
getfixturedefs: Callable[[str], Sequence[FixtureDef[Any]] | None],
)
| 339 | |
| 340 | |
| 341 | def traverse_fixture_closure( |
| 342 | initialnames: Iterable[str], |
| 343 | *, |
| 344 | getfixturedefs: Callable[[str], Sequence[FixtureDef[Any]] | None], |
| 345 | ) -> Iterator[str]: |
| 346 | """Statically traverse the fixture dependency closure in DFS order starting |
| 347 | from initialnames, yielding all requested fixture names (argnames). |
| 348 | |
| 349 | Each argname is only yielded once. |
| 350 | """ |
| 351 | # Track the index for each fixture name in the simulated stack. |
| 352 | # Needed for handling override chains correctly, similar to |
| 353 | # FixtureRequest._get_active_fixturedef. |
| 354 | # Using negative indices: -1 is the most specific (last), -2 is second to |
| 355 | # last, etc. |
| 356 | current_indices: dict[str, int] = {} |
| 357 | |
| 358 | def process_argname(argname: str) -> Iterator[str]: |
| 359 | index = current_indices.get(argname) |
| 360 | |
| 361 | # Optimization: already processed this argname. |
| 362 | if index == -1: |
| 363 | return |
| 364 | |
| 365 | # Only yield each argname once. |
| 366 | if index is None: |
| 367 | yield argname |
| 368 | current_indices[argname] = -1 |
| 369 | |
| 370 | fixturedefs = getfixturedefs(argname) |
| 371 | if not fixturedefs: |
| 372 | return |
| 373 | |
| 374 | index = current_indices.get(argname, -1) |
| 375 | if -index > len(fixturedefs): |
| 376 | # Exhausted the override chain (will error during runtest). |
| 377 | return |
| 378 | fixturedef = fixturedefs[index] |
| 379 | |
| 380 | current_indices[argname] = index - 1 |
| 381 | for dep in fixturedef.argnames: |
| 382 | yield from process_argname(dep) |
| 383 | current_indices[argname] = index |
| 384 | |
| 385 | for argname in initialnames: |
| 386 | yield from process_argname(argname) |
| 387 | |
| 388 | |
| 389 | @dataclasses.dataclass(frozen=True) |
no test coverage detected