MCPcopy
hub / github.com/pytest-dev/pytest / getfixtureclosure

Method getfixtureclosure

src/_pytest/fixtures.py:1853–1898  ·  view source on GitHub ↗
(
        self,
        parentnode: nodes.Node,
        initialnames: tuple[str, ...],
        ignore_args: AbstractSet[str],
    )

Source from the content-addressed store, hash-verified

1851 yield from mark.args
1852
1853 def getfixtureclosure(
1854 self,
1855 parentnode: nodes.Node,
1856 initialnames: tuple[str, ...],
1857 ignore_args: AbstractSet[str],
1858 ) -> tuple[list[str], dict[str, Sequence[FixtureDef[Any]]]]:
1859 # Collect the closure of all fixtures, starting with the given
1860 # fixturenames as the initial set. As we have to visit all
1861 # factory definitions anyway, we also return an arg2fixturedefs
1862 # mapping so that the caller can reuse it and does not have
1863 # to re-discover fixturedefs again for each fixturename
1864 # (discovering matching fixtures for a given name/node is expensive).
1865
1866 arg2fixturedefs: dict[str, Sequence[FixtureDef[Any]]] = {}
1867
1868 def getfixturedefs(argname: str) -> Sequence[FixtureDef[Any]] | None:
1869 if argname in ignore_args:
1870 return None
1871
1872 fixturedefs = arg2fixturedefs.get(argname)
1873 if not fixturedefs:
1874 fixturedefs = self.getfixturedefs(argname, parentnode)
1875 if not fixturedefs:
1876 # Fixture not defined or not visible (will error during runtest).
1877 return None
1878 arg2fixturedefs[argname] = fixturedefs
1879 return fixturedefs
1880
1881 def sort_by_scope(arg_name: str) -> Scope:
1882 try:
1883 fixturedefs = arg2fixturedefs[arg_name]
1884 except KeyError:
1885 return Scope.Function
1886 else:
1887 return fixturedefs[-1]._scope
1888
1889 fixturenames_closure = sorted(
1890 traverse_fixture_closure(
1891 initialnames,
1892 getfixturedefs=getfixturedefs,
1893 ),
1894 key=sort_by_scope,
1895 reverse=True,
1896 )
1897
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"""

Callers 1

getfixtureinfoMethod · 0.95

Calls 1

traverse_fixture_closureFunction · 0.85

Tested by

no test coverage detected