introduce a pytest_collect_metainfo hook
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									69214d053d
								
							
						
					
					
						commit
						4956e00a49
					
				| 
						 | 
					@ -53,6 +53,11 @@ class PluginHooks:
 | 
				
			||||||
        """ return custom item/collector for a python object in a module, or None.  """
 | 
					        """ return custom item/collector for a python object in a module, or None.  """
 | 
				
			||||||
    pytest_pycollect_obj.firstresult = True
 | 
					    pytest_pycollect_obj.firstresult = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def pytest_collect_metainfo(self, colitem):
 | 
				
			||||||
 | 
					        """ return (fspath, lineno, name) for the colitem.
 | 
				
			||||||
 | 
					            the information is used for result display and to sort tests
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def pytest_genfunc(self, funcspec):
 | 
					    def pytest_genfunc(self, funcspec):
 | 
				
			||||||
        """ generate (multiple) parametrized calls to a test function."""
 | 
					        """ generate (multiple) parametrized calls to a test function."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -82,6 +82,9 @@ class PyobjMixin(object):
 | 
				
			||||||
        return self._fslineno
 | 
					        return self._fslineno
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def metainfo(self):
 | 
					    def metainfo(self):
 | 
				
			||||||
 | 
					        res = self.config.hook.pytest_collect_metainfo(colitem=self)
 | 
				
			||||||
 | 
					        if res:
 | 
				
			||||||
 | 
					            return res
 | 
				
			||||||
        fspath, lineno = self._getfslineno()
 | 
					        fspath, lineno = self._getfslineno()
 | 
				
			||||||
        modpath = self.getmodpath()
 | 
					        modpath = self.getmodpath()
 | 
				
			||||||
        return fspath, lineno, modpath 
 | 
					        return fspath, lineno, modpath 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -397,3 +397,18 @@ class TestMetaInfo:
 | 
				
			||||||
                def test_method(self):
 | 
					                def test_method(self):
 | 
				
			||||||
                    pass
 | 
					                    pass
 | 
				
			||||||
       """
 | 
					       """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_pytest_collect_metainfo(self, testdir):
 | 
				
			||||||
 | 
					        wascalled = []
 | 
				
			||||||
 | 
					        class Plugin:
 | 
				
			||||||
 | 
					            def pytest_collect_metainfo(self, colitem):
 | 
				
			||||||
 | 
					                wascalled.append(colitem)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        item = testdir.getitem("def test_func(): pass")
 | 
				
			||||||
 | 
					        item.config.pluginmanager.register(Plugin())      
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        fspath, lineno, modpath = item.metainfo()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert wascalled == [item]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue