summaryrefslogtreecommitdiff
path: root/src/_pytest/main.py
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-08-21 14:19:14 +0300
committerRan Benita <ran@unusedvar.com>2020-08-24 18:15:11 +0300
commita2c919d350e5f52287a42187853ed0e090168fe1 (patch)
tree2921ad9a7508defe56acc12e30dfd2c81b9a9bbe /src/_pytest/main.py
parentadaec2da90c006e4c3317e49b8cbb3f5b6a8dc72 (diff)
downloadpytest-a2c919d350e5f52287a42187853ed0e090168fe1.tar.gz
main: refactor a bit to reduce indentation
Diffstat (limited to 'src/_pytest/main.py')
-rw-r--r--src/_pytest/main.py60
1 files changed, 28 insertions, 32 deletions
diff --git a/src/_pytest/main.py b/src/_pytest/main.py
index 602f5fbd2..1f7340720 100644
--- a/src/_pytest/main.py
+++ b/src/_pytest/main.py
@@ -748,38 +748,34 @@ class Session(nodes.FSCollector):
self.trace("matchnodes", matching, names)
self.trace.root.indent += 1
- if not names:
- result = matching
- else:
- name = names[0]
- assert name
- resultnodes = [] # type: List[Union[nodes.Item, nodes.Collector]]
- for node in matching:
- if isinstance(node, nodes.Item):
- continue
- assert isinstance(node, nodes.Collector)
- key = (type(node), node.nodeid)
- if key in self._collection_node_cache3:
- rep = self._collection_node_cache3[key]
- else:
- rep = collect_one_node(node)
- self._collection_node_cache3[key] = rep
- if rep.passed:
- has_matched = False
- for x in rep.result:
- # TODO: Remove parametrized workaround once collection structure contains parametrization.
- if x.name == name or x.name.split("[")[0] == name:
- resultnodes.extend(self.matchnodes([x], names[1:]))
- has_matched = True
- # XXX Accept IDs that don't have "()" for class instances.
- if not has_matched and len(rep.result) == 1 and x.name == "()":
- resultnodes.extend(self.matchnodes([x], names))
- else:
- # Report collection failures here to avoid failing to run some test
- # specified in the command line because the module could not be
- # imported (#134).
- node.ihook.pytest_collectreport(report=rep)
- result = resultnodes
+ result = []
+ for node in matching:
+ if not names:
+ result.append(node)
+ continue
+ if not isinstance(node, nodes.Collector):
+ continue
+ key = (type(node), node.nodeid)
+ if key in self._collection_node_cache3:
+ rep = self._collection_node_cache3[key]
+ else:
+ rep = collect_one_node(node)
+ self._collection_node_cache3[key] = rep
+ if rep.passed:
+ has_matched = False
+ for x in rep.result:
+ # TODO: Remove parametrized workaround once collection structure contains parametrization.
+ if x.name == names[0] or x.name.split("[")[0] == names[0]:
+ result.extend(self.matchnodes([x], names[1:]))
+ has_matched = True
+ # XXX Accept IDs that don't have "()" for class instances.
+ if not has_matched and len(rep.result) == 1 and x.name == "()":
+ result.extend(self.matchnodes([x], names))
+ else:
+ # Report collection failures here to avoid failing to run some test
+ # specified in the command line because the module could not be
+ # imported (#134).
+ node.ihook.pytest_collectreport(report=rep)
self.trace("matchnodes finished -> ", len(result), "nodes")
self.trace.root.indent -= 1