Return list of keys for all parametrized arguments which match the specified scope.
(item: nodes.Item, scope: Scope)
| 241 | |
| 242 | |
| 243 | def get_parametrized_fixture_keys(item: nodes.Item, scope: Scope) -> Iterator[_Key]: |
| 244 | """Return list of keys for all parametrized arguments which match |
| 245 | the specified scope.""" |
| 246 | assert scope is not Scope.Function |
| 247 | try: |
| 248 | callspec = item.callspec # type: ignore[attr-defined] |
| 249 | except AttributeError: |
| 250 | pass |
| 251 | else: |
| 252 | cs: CallSpec2 = callspec |
| 253 | # cs.indices.items() is random order of argnames. Need to |
| 254 | # sort this so that different calls to |
| 255 | # get_parametrized_fixture_keys will be deterministic. |
| 256 | for argname, param_index in sorted(cs.indices.items()): |
| 257 | if cs._arg2scope[argname] != scope: |
| 258 | continue |
| 259 | if scope is Scope.Session: |
| 260 | key: _Key = (argname, param_index) |
| 261 | elif scope is Scope.Package: |
| 262 | key = (argname, param_index, item.path.parent) |
| 263 | elif scope is Scope.Module: |
| 264 | key = (argname, param_index, item.path) |
| 265 | elif scope is Scope.Class: |
| 266 | item_cls = item.cls # type: ignore[attr-defined] |
| 267 | key = (argname, param_index, item.path, item_cls) |
| 268 | else: |
| 269 | assert_never(scope) |
| 270 | yield key |
| 271 | |
| 272 | |
| 273 | # Algorithm for sorting on a per-parametrized resource setup basis. |
no test coverage detected