Generate new tests based on parametrized fixtures used by the given metafunc
(self, metafunc: Metafunc)
| 1898 | return fixturenames_closure, arg2fixturedefs |
| 1899 | |
| 1900 | def pytest_generate_tests(self, metafunc: Metafunc) -> None: |
| 1901 | """Generate new tests based on parametrized fixtures used by the given metafunc""" |
| 1902 | |
| 1903 | def get_parametrize_mark_argnames(mark: Mark) -> Sequence[str]: |
| 1904 | args, _ = ParameterSet._parse_parametrize_args(*mark.args, **mark.kwargs) |
| 1905 | return args |
| 1906 | |
| 1907 | for argname in metafunc.fixturenames: |
| 1908 | # Get the FixtureDefs for the argname. |
| 1909 | fixture_defs = metafunc._arg2fixturedefs.get(argname, ()) |
| 1910 | |
| 1911 | # If the test itself parametrizes using this argname, give it |
| 1912 | # precedence. |
| 1913 | if any( |
| 1914 | argname in get_parametrize_mark_argnames(mark) |
| 1915 | for mark in metafunc.definition.iter_markers("parametrize") |
| 1916 | ): |
| 1917 | continue |
| 1918 | |
| 1919 | # In the common case we only look at the fixture def with the |
| 1920 | # closest scope (last in the list). But if the fixture overrides |
| 1921 | # another fixture, while requesting the super fixture, keep going |
| 1922 | # in case the super fixture is parametrized (#1953). |
| 1923 | for fixturedef in reversed(fixture_defs): |
| 1924 | # Fixture is parametrized, apply it and stop. |
| 1925 | if fixturedef.params is not None: |
| 1926 | metafunc.parametrize( |
| 1927 | argname, |
| 1928 | fixturedef.params, |
| 1929 | indirect=True, |
| 1930 | scope=fixturedef.scope, |
| 1931 | ids=fixturedef.ids, |
| 1932 | ) |
| 1933 | break |
| 1934 | |
| 1935 | # Not requesting the overridden super fixture, stop. |
| 1936 | # |
| 1937 | # TODO: Handle the case where the super-fixture is transitively |
| 1938 | # requested (see #7737 and the xfail'd test |
| 1939 | # test_override_parametrized_fixture_via_transitive_fixture). |
| 1940 | if argname not in fixturedef.argnames: |
| 1941 | break |
| 1942 | |
| 1943 | # Try next super fixture, if any. |
| 1944 | |
| 1945 | def pytest_collection_modifyitems(self, items: list[nodes.Item]) -> None: |
| 1946 | # Separate parametrized setups. |
nothing calls this directly
no test coverage detected