Find the most appropriate scope for a parametrized call based on its arguments. When there's at least one direct argument, always use "function" scope. When a test function is parametrized and all its arguments are indirect (e.g. fixtures), return the most narrow scope based on the fix
(
argnames: Sequence[str],
arg2fixturedefs: Mapping[str, Sequence[fixtures.FixtureDef[object]]],
indirect: Union[bool, Sequence[str]],
)
| 1316 | |
| 1317 | |
| 1318 | def _find_parametrized_scope( |
| 1319 | argnames: Sequence[str], |
| 1320 | arg2fixturedefs: Mapping[str, Sequence[fixtures.FixtureDef[object]]], |
| 1321 | indirect: Union[bool, Sequence[str]], |
| 1322 | ) -> Scope: |
| 1323 | """Find the most appropriate scope for a parametrized call based on its arguments. |
| 1324 | |
| 1325 | When there's at least one direct argument, always use "function" scope. |
| 1326 | |
| 1327 | When a test function is parametrized and all its arguments are indirect |
| 1328 | (e.g. fixtures), return the most narrow scope based on the fixtures used. |
| 1329 | |
| 1330 | Related to issue #1832, based on code posted by @Kingdread. |
| 1331 | """ |
| 1332 | if isinstance(indirect, Sequence): |
| 1333 | all_arguments_are_fixtures = len(indirect) == len(argnames) |
| 1334 | else: |
| 1335 | all_arguments_are_fixtures = bool(indirect) |
| 1336 | |
| 1337 | if all_arguments_are_fixtures: |
| 1338 | fixturedefs = arg2fixturedefs or {} |
| 1339 | used_scopes = [ |
| 1340 | fixturedef[0]._scope |
| 1341 | for name, fixturedef in fixturedefs.items() |
| 1342 | if name in argnames |
| 1343 | ] |
| 1344 | # Takes the most narrow scope from used fixtures. |
| 1345 | return min(used_scopes, default=Scope.Function) |
| 1346 | |
| 1347 | return Scope.Function |
| 1348 | |
| 1349 | |
| 1350 | def _ascii_escaped_by_config(val: Union[str, bytes], config: Optional[Config]) -> str: |
no outgoing calls
no test coverage detected