Generate new tests based on parametrized fixtures used by the given metafunc
(self, metafunc: "Metafunc")
| 1550 | return initialnames, fixturenames_closure, arg2fixturedefs |
| 1551 | |
| 1552 | def pytest_generate_tests(self, metafunc: "Metafunc") -> None: |
| 1553 | """Generate new tests based on parametrized fixtures used by the given metafunc""" |
| 1554 | |
| 1555 | def get_parametrize_mark_argnames(mark: Mark) -> Sequence[str]: |
| 1556 | args, _ = ParameterSet._parse_parametrize_args(*mark.args, **mark.kwargs) |
| 1557 | return args |
| 1558 | |
| 1559 | for argname in metafunc.fixturenames: |
| 1560 | # Get the FixtureDefs for the argname. |
| 1561 | fixture_defs = metafunc._arg2fixturedefs.get(argname) |
| 1562 | if not fixture_defs: |
| 1563 | # Will raise FixtureLookupError at setup time if not parametrized somewhere |
| 1564 | # else (e.g @pytest.mark.parametrize) |
| 1565 | continue |
| 1566 | |
| 1567 | # If the test itself parametrizes using this argname, give it |
| 1568 | # precedence. |
| 1569 | if any( |
| 1570 | argname in get_parametrize_mark_argnames(mark) |
| 1571 | for mark in metafunc.definition.iter_markers("parametrize") |
| 1572 | ): |
| 1573 | continue |
| 1574 | |
| 1575 | # In the common case we only look at the fixture def with the |
| 1576 | # closest scope (last in the list). But if the fixture overrides |
| 1577 | # another fixture, while requesting the super fixture, keep going |
| 1578 | # in case the super fixture is parametrized (#1953). |
| 1579 | for fixturedef in reversed(fixture_defs): |
| 1580 | # Fixture is parametrized, apply it and stop. |
| 1581 | if fixturedef.params is not None: |
| 1582 | metafunc.parametrize( |
| 1583 | argname, |
| 1584 | fixturedef.params, |
| 1585 | indirect=True, |
| 1586 | scope=fixturedef.scope, |
| 1587 | ids=fixturedef.ids, |
| 1588 | ) |
| 1589 | break |
| 1590 | |
| 1591 | # Not requesting the overridden super fixture, stop. |
| 1592 | if argname not in fixturedef.argnames: |
| 1593 | break |
| 1594 | |
| 1595 | # Try next super fixture, if any. |
| 1596 | |
| 1597 | def pytest_collection_modifyitems(self, items: List[nodes.Item]) -> None: |
| 1598 | # Separate parametrized setups. |
nothing calls this directly
no test coverage detected