fixtures: change _getautousenames to an iterator
This reads better.
This commit is contained in:
parent
aa0e2d654f
commit
d6becfa177
|
@ -1476,14 +1476,12 @@ class FixtureManager:
|
||||||
|
|
||||||
self.parsefactories(plugin, nodeid)
|
self.parsefactories(plugin, nodeid)
|
||||||
|
|
||||||
def _getautousenames(self, nodeid: str) -> List[str]:
|
def _getautousenames(self, nodeid: str) -> Iterator[str]:
|
||||||
"""Return a list of fixture names to be used."""
|
"""Return the names of autouse fixtures applicable to nodeid."""
|
||||||
parentnodeids = set(nodes.iterparentnodeids(nodeid))
|
parentnodeids = set(nodes.iterparentnodeids(nodeid))
|
||||||
autousenames: List[str] = []
|
|
||||||
for baseid, basenames in self._nodeid_and_autousenames:
|
for baseid, basenames in self._nodeid_and_autousenames:
|
||||||
if baseid in parentnodeids:
|
if baseid in parentnodeids:
|
||||||
autousenames.extend(basenames)
|
yield from basenames
|
||||||
return autousenames
|
|
||||||
|
|
||||||
def getfixtureclosure(
|
def getfixtureclosure(
|
||||||
self,
|
self,
|
||||||
|
@ -1499,7 +1497,7 @@ class FixtureManager:
|
||||||
# (discovering matching fixtures for a given name/node is expensive).
|
# (discovering matching fixtures for a given name/node is expensive).
|
||||||
|
|
||||||
parentid = parentnode.nodeid
|
parentid = parentnode.nodeid
|
||||||
fixturenames_closure = self._getautousenames(parentid)
|
fixturenames_closure = list(self._getautousenames(parentid))
|
||||||
|
|
||||||
def merge(otherlist: Iterable[str]) -> None:
|
def merge(otherlist: Iterable[str]) -> None:
|
||||||
for arg in otherlist:
|
for arg in otherlist:
|
||||||
|
|
|
@ -1710,7 +1710,7 @@ class TestAutouseDiscovery:
|
||||||
"""
|
"""
|
||||||
from _pytest.pytester import get_public_names
|
from _pytest.pytester import get_public_names
|
||||||
def test_check_setup(item, fm):
|
def test_check_setup(item, fm):
|
||||||
autousenames = fm._getautousenames(item.nodeid)
|
autousenames = list(fm._getautousenames(item.nodeid))
|
||||||
assert len(get_public_names(autousenames)) == 2
|
assert len(get_public_names(autousenames)) == 2
|
||||||
assert "perfunction2" in autousenames
|
assert "perfunction2" in autousenames
|
||||||
assert "perfunction" in autousenames
|
assert "perfunction" in autousenames
|
||||||
|
|
Loading…
Reference in New Issue