test and fix tracing indentation in case of exceptions
This commit is contained in:
		
							parent
							
								
									1899443744
								
							
						
					
					
						commit
						b3628daa62
					
				|  | @ -389,10 +389,12 @@ class HookCaller: | ||||||
|         self.trace(self.name, kwargs) |         self.trace(self.name, kwargs) | ||||||
|         self.trace.root.indent += 1 |         self.trace.root.indent += 1 | ||||||
|         mc = MultiCall(methods, kwargs, firstresult=self.firstresult) |         mc = MultiCall(methods, kwargs, firstresult=self.firstresult) | ||||||
|         res = mc.execute() |         try: | ||||||
|         if res: |             res = mc.execute() | ||||||
|             self.trace(res) |             if res: | ||||||
|         self.trace.root.indent -= 1 |                 self.trace(res) | ||||||
|  |         finally: | ||||||
|  |             self.trace.root.indent -= 1 | ||||||
|         return res |         return res | ||||||
| 
 | 
 | ||||||
| _preinit = [PluginManager(load=True)] # triggers default plugin importing | _preinit = [PluginManager(load=True)] # triggers default plugin importing | ||||||
|  |  | ||||||
|  | @ -266,18 +266,26 @@ class TestBootstrapping: | ||||||
|         l = list(plugins.listattr('x')) |         l = list(plugins.listattr('x')) | ||||||
|         assert l == [41, 42, 43] |         assert l == [41, 42, 43] | ||||||
| 
 | 
 | ||||||
|     def test_register_trace(self): |     def test_hook_tracing(self): | ||||||
|         pm = PluginManager() |         pm = PluginManager() | ||||||
|  |         saveindent = [] | ||||||
|         class api1: |         class api1: | ||||||
|             x = 41 |             x = 41 | ||||||
|  |             def pytest_plugin_registered(self, plugin): | ||||||
|  |                 saveindent.append(pm.trace.root.indent) | ||||||
|  |                 raise ValueError(42) | ||||||
|         l = [] |         l = [] | ||||||
|         pm.trace.setmyprocessor(lambda kw, args: l.append((kw, args))) |         pm.trace.root.setwriter(l.append) | ||||||
|  |         indent = pm.trace.root.indent | ||||||
|         p = api1() |         p = api1() | ||||||
|         pm.register(p) |         pm.register(p) | ||||||
|  | 
 | ||||||
|  |         assert pm.trace.root.indent == indent | ||||||
|         assert len(l) == 1 |         assert len(l) == 1 | ||||||
|         kw, args = l[0] |         assert 'pytest_plugin_registered' in l[0] | ||||||
|         assert args[0] == "registered" |         py.test.raises(ValueError, lambda: pm.register(api1())) | ||||||
|         assert args[1] == p |         assert pm.trace.root.indent == indent | ||||||
|  |         assert saveindent[0] > indent | ||||||
| 
 | 
 | ||||||
| class TestPytestPluginInteractions: | class TestPytestPluginInteractions: | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue