remove superflous building of a dict, preserve order for nodes that have identical file:lineno
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									1ff37207a2
								
							
						
					
					
						commit
						ee2f292efa
					
				|  | @ -76,18 +76,12 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector): | ||||||
|         l = self._deprecated_collect() |         l = self._deprecated_collect() | ||||||
|         if l is not None: |         if l is not None: | ||||||
|             return l |             return l | ||||||
|         name2items = self._buildname2items() |  | ||||||
|         colitems = list(name2items.values()) |  | ||||||
|         colitems.sort(key=lambda item: item.reportinfo()[:2]) |  | ||||||
|         return colitems |  | ||||||
| 
 |  | ||||||
|     def _buildname2items(self):  |  | ||||||
|         # NB. we avoid random getattrs and peek in the __dict__ instead |         # NB. we avoid random getattrs and peek in the __dict__ instead | ||||||
|         d = {} |  | ||||||
|         dicts = [getattr(self.obj, '__dict__', {})] |         dicts = [getattr(self.obj, '__dict__', {})] | ||||||
|         for basecls in inspect.getmro(self.obj.__class__): |         for basecls in inspect.getmro(self.obj.__class__): | ||||||
|             dicts.append(basecls.__dict__) |             dicts.append(basecls.__dict__) | ||||||
|         seen = {} |         seen = {} | ||||||
|  |         l = [] | ||||||
|         for dic in dicts: |         for dic in dicts: | ||||||
|             for name, obj in dic.items(): |             for name, obj in dic.items(): | ||||||
|                 if name in seen: |                 if name in seen: | ||||||
|  | @ -96,8 +90,9 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector): | ||||||
|                 if name[0] != "_": |                 if name[0] != "_": | ||||||
|                     res = self.makeitem(name, obj) |                     res = self.makeitem(name, obj) | ||||||
|                     if res is not None: |                     if res is not None: | ||||||
|                         d[name] = res  |                         l.append(res) | ||||||
|         return d |         l.sort(key=lambda item: item.reportinfo()[:2]) | ||||||
|  |         return l | ||||||
| 
 | 
 | ||||||
|     def _deprecated_join(self, name): |     def _deprecated_join(self, name): | ||||||
|         if self.__class__.join != py.test.collect.Collector.join: |         if self.__class__.join != py.test.collect.Collector.join: | ||||||
|  |  | ||||||
|  | @ -333,7 +333,7 @@ class TestConftestCustomization: | ||||||
|         l = [] |         l = [] | ||||||
|         monkeypatch.setattr(py.test.collect.Module, 'makeitem',  |         monkeypatch.setattr(py.test.collect.Module, 'makeitem',  | ||||||
|             lambda self, name, obj: l.append(name)) |             lambda self, name, obj: l.append(name)) | ||||||
|         modcol._buildname2items() |         l = modcol.collect() | ||||||
|         assert '_hello' not in l |         assert '_hello' not in l | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue