Returns all fixtures used by the test item except for those created by direct parametrization and those requested dynamically with ``request.getfixturevalue``. The justification for excluding fixtures created by direct parametrization is that for users, they are internal implementat
(test: nodes.Item)
| 2188 | |
| 2189 | |
| 2190 | def _get_fixtures_per_test(test: nodes.Item) -> Iterator[FixtureDef[object]]: |
| 2191 | """Returns all fixtures used by the test item except for those created by |
| 2192 | direct parametrization and those requested dynamically with |
| 2193 | ``request.getfixturevalue``. |
| 2194 | |
| 2195 | The justification for excluding fixtures created by direct parametrization |
| 2196 | is that for users, they are internal implementation detail. |
| 2197 | |
| 2198 | Dynamically requested fixtures are excluded because they are not known |
| 2199 | statically. |
| 2200 | """ |
| 2201 | from _pytest.python import DirectParamFixtureDef |
| 2202 | |
| 2203 | # Custom Items may not have _fixtureinfo attribute. |
| 2204 | fixture_info: FuncFixtureInfo | None = getattr(test, "_fixtureinfo", None) |
| 2205 | if fixture_info is None: |
| 2206 | return # pragma: no cover |
| 2207 | |
| 2208 | # dict key not used in loop but needed for sorting. |
| 2209 | for argname, fixturedefs in sorted(fixture_info.name2fixturedefs.items()): |
| 2210 | if not fixturedefs: |
| 2211 | # Not supposed to be empty, but for safety. |
| 2212 | continue # pragma: no cover |
| 2213 | # Last item is expected to be the one directly used by the test item. |
| 2214 | fixturedef = fixturedefs[-1] |
| 2215 | if isinstance(fixturedef, DirectParamFixtureDef): |
| 2216 | continue |
| 2217 | yield fixturedef |
| 2218 | |
| 2219 | |
| 2220 | def _show_fixtures_per_test(config: Config, session: Session) -> None: |