main: inline Session._perform_collect() into perform_collect()

It doesn't add much, mostly just an eye sore, particularly with the
overloads.
This commit is contained in:
Ran Benita 2020-08-15 11:58:44 +03:00
parent 1dad5c6433
commit d121d7c917
1 changed files with 38 additions and 48 deletions

View File

@ -552,41 +552,20 @@ class Session(nodes.FSCollector):
in which case the return value contains these collectors unexpanded,
and ``session.items`` is empty.
"""
hook = self.config.hook
try:
items = self._perform_collect(args, genitems)
self.config.pluginmanager.check_pending()
hook.pytest_collection_modifyitems(
session=self, config=self.config, items=items
)
finally:
hook.pytest_collection_finish(session=self)
self.testscollected = len(items)
return items
@overload
def _perform_collect(
self, args: Optional[Sequence[str]], genitems: "Literal[True]"
) -> List[nodes.Item]:
...
@overload # noqa: F811
def _perform_collect( # noqa: F811
self, args: Optional[Sequence[str]], genitems: bool
) -> Union[List[Union[nodes.Item]], List[Union[nodes.Item, nodes.Collector]]]:
...
def _perform_collect( # noqa: F811
self, args: Optional[Sequence[str]], genitems: bool
) -> Union[List[Union[nodes.Item]], List[Union[nodes.Item, nodes.Collector]]]:
if args is None:
args = self.config.args
self.trace("perform_collect", self, args)
self.trace.root.indent += 1
self._notfound = [] # type: List[Tuple[str, NoMatch]]
initialpaths = [] # type: List[py.path.local]
self._initial_parts = [] # type: List[Tuple[py.path.local, List[str]]]
self.items = items = [] # type: List[nodes.Item]
hook = self.config.hook
try:
initialpaths = [] # type: List[py.path.local]
for arg in args:
fspath, parts = resolve_collection_argument(
self.config.invocation_dir, arg, as_pypath=self.config.option.pyargs
@ -604,11 +583,22 @@ class Session(nodes.FSCollector):
errors.append("not found: {}\n{}".format(arg, line))
raise UsageError(*errors)
if not genitems:
return rep.result
# Type ignored because genitems=False is only used by tests. We don't
# want to change the type of `session.items` for this case.
items = rep.result # type: ignore[assignment]
else:
if rep.passed:
for node in rep.result:
self.items.extend(self.genitems(node))
self.config.pluginmanager.check_pending()
hook.pytest_collection_modifyitems(
session=self, config=self.config, items=items
)
finally:
hook.pytest_collection_finish(session=self)
self.testscollected = len(items)
return items
def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]: