From 89eee90b5f3e112d295d1aeb546a37234ce91faf Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 30 Apr 2020 20:13:26 +0300 Subject: [PATCH] python: optimize PythonCollector.collect --- src/_pytest/python.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index e1bd62f0b..8186b9af1 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -365,15 +365,17 @@ class PyCollector(PyobjMixin, nodes.Collector): # NB. we avoid random getattrs and peek in the __dict__ instead # (XXX originally introduced from a PyPy need, still true?) dicts = [getattr(self.obj, "__dict__", {})] - for basecls in inspect.getmro(self.obj.__class__): + for basecls in self.obj.__class__.__mro__: dicts.append(basecls.__dict__) - seen = {} + seen = set() values = [] for dic in dicts: + # Note: seems like the dict can change during iteration - + # be careful not to remove the list() without consideration. for name, obj in list(dic.items()): if name in seen: continue - seen[name] = True + seen.add(name) res = self._makeitem(name, obj) if res is None: continue