|
53 | 53 | from _pytest.config import hookimpl |
54 | 54 | from _pytest.config.argparsing import Parser |
55 | 55 | from _pytest.deprecated import check_ispytest |
| 56 | +from _pytest.fixtures import _resolve_args_directness |
56 | 57 | from _pytest.fixtures import FixtureDef |
57 | 58 | from _pytest.fixtures import FixtureRequest |
58 | 59 | from _pytest.fixtures import FuncFixtureInfo |
@@ -1327,7 +1328,9 @@ def parametrize( |
1327 | 1328 | object.__setattr__(_param_mark._param_ids_from, "_param_ids_generated", ids) |
1328 | 1329 |
|
1329 | 1330 | # Calculate directness. |
1330 | | - arg_directness = self._resolve_args_directness(argnames, indirect) |
| 1331 | + arg_directness = _resolve_args_directness( |
| 1332 | + argnames, indirect, self.definition.nodeid |
| 1333 | + ) |
1331 | 1334 | self._params_directness.update(arg_directness) |
1332 | 1335 |
|
1333 | 1336 | # Add direct parametrizations as fixturedefs to arg2fixturedefs by |
@@ -1464,45 +1467,6 @@ def _validate_ids( |
1464 | 1467 |
|
1465 | 1468 | return list(itertools.islice(ids, num_ids)) |
1466 | 1469 |
|
1467 | | - def _resolve_args_directness( |
1468 | | - self, |
1469 | | - argnames: Sequence[str], |
1470 | | - indirect: bool | Sequence[str], |
1471 | | - ) -> dict[str, Literal["indirect", "direct"]]: |
1472 | | - """Resolve if each parametrized argument must be considered an indirect |
1473 | | - parameter to a fixture of the same name, or a direct parameter to the |
1474 | | - parametrized function, based on the ``indirect`` parameter of the |
1475 | | - parametrized() call. |
1476 | | -
|
1477 | | - :param argnames: |
1478 | | - List of argument names passed to ``parametrize()``. |
1479 | | - :param indirect: |
1480 | | - Same as the ``indirect`` parameter of ``parametrize()``. |
1481 | | - :returns |
1482 | | - A dict mapping each arg name to either "indirect" or "direct". |
1483 | | - """ |
1484 | | - nodeid = self.definition.nodeid |
1485 | | - arg_directness: dict[str, Literal["indirect", "direct"]] |
1486 | | - if isinstance(indirect, bool): |
1487 | | - arg_directness = dict.fromkeys( |
1488 | | - argnames, "indirect" if indirect else "direct" |
1489 | | - ) |
1490 | | - elif isinstance(indirect, Sequence): |
1491 | | - arg_directness = dict.fromkeys(argnames, "direct") |
1492 | | - for arg in indirect: |
1493 | | - if arg not in argnames: |
1494 | | - fail( |
1495 | | - f"In {nodeid}: indirect fixture '{arg}' doesn't exist", |
1496 | | - pytrace=False, |
1497 | | - ) |
1498 | | - arg_directness[arg] = "indirect" |
1499 | | - else: |
1500 | | - fail( |
1501 | | - f"In {nodeid}: expected Sequence or boolean for indirect, got {type(indirect).__name__}", |
1502 | | - pytrace=False, |
1503 | | - ) |
1504 | | - return arg_directness |
1505 | | - |
1506 | 1470 | def _validate_if_using_arg_names( |
1507 | 1471 | self, |
1508 | 1472 | argnames: Sequence[str], |
|
0 commit comments