[svn r63579] step one in simplifying runtest() collect() semantics
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									85635e1239
								
							
						
					
					
						commit
						245da9de19
					
				|  | @ -11,7 +11,6 @@ import py, os, sys | ||||||
| from py.__.test import event | from py.__.test import event | ||||||
| from py.__.test.outcome import Exit | from py.__.test.outcome import Exit | ||||||
| from py.__.test.dist.mypickle import ImmutablePickler | from py.__.test.dist.mypickle import ImmutablePickler | ||||||
| import py.__.test.custompdb |  | ||||||
| 
 | 
 | ||||||
| class RobustRun(object): | class RobustRun(object): | ||||||
|     """ a robust setup/execute/teardown protocol used both for test collectors  |     """ a robust setup/execute/teardown protocol used both for test collectors  | ||||||
|  | @ -25,20 +24,22 @@ class RobustRun(object): | ||||||
|     def __repr__(self): |     def __repr__(self): | ||||||
|         return "<%s colitem=%s>" %(self.__class__.__name__, self.colitem) |         return "<%s colitem=%s>" %(self.__class__.__name__, self.colitem) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | class ItemRunner(RobustRun): | ||||||
|     def run(self): |     def run(self): | ||||||
|         """ return result of running setup, execution, teardown procedures. """  |         """ return result of running setup, execution, teardown procedures. """  | ||||||
|         excinfo = None |         excinfo = None | ||||||
|         res = NORESULT |  | ||||||
|         capture = self.getcapture() |         capture = self.getcapture() | ||||||
|         try: |         try: | ||||||
|             try: |             try: | ||||||
|                 when = "setup" |                 when = "setup" | ||||||
|                 self.setup() |                 self.colitem.config._setupstate.prepare(self.colitem) | ||||||
|                 try: |                 try: | ||||||
|                     res = self.execute() |                     when = "execute" | ||||||
|  |                     res = self.colitem.runtest() | ||||||
|                 finally: |                 finally: | ||||||
|                     when = "teardown" |                     when = "teardown" | ||||||
|                     self.teardown() |                     self.colitem.config._setupstate.teardown_exact(self.colitem) | ||||||
|                     when = "execute" |                     when = "execute" | ||||||
|             finally: |             finally: | ||||||
|                 outerr = capture.reset() |                 outerr = capture.reset() | ||||||
|  | @ -46,19 +47,9 @@ class RobustRun(object): | ||||||
|             raise |             raise | ||||||
|         except:  |         except:  | ||||||
|             excinfo = py.code.ExceptionInfo() |             excinfo = py.code.ExceptionInfo() | ||||||
|         return self.makereport(res, when, excinfo, outerr) |         return self.makereport(when, excinfo, outerr) | ||||||
| 
 | 
 | ||||||
| class ItemRunner(RobustRun): |     def makereport(self, when, excinfo, outerr): | ||||||
|     def setup(self): |  | ||||||
|         self.colitem.config._setupstate.prepare(self.colitem) |  | ||||||
|     def teardown(self): |  | ||||||
|         self.colitem.config._setupstate.teardown_exact(self.colitem) |  | ||||||
|     def execute(self): |  | ||||||
|         #self.colitem.config.pytestplugins.pre_execute(self.colitem) |  | ||||||
|         self.colitem.runtest() |  | ||||||
|         #self.colitem.config.pytestplugins.post_execute(self.colitem) |  | ||||||
| 
 |  | ||||||
|     def makereport(self, res, when, excinfo, outerr): |  | ||||||
|         testrep = self.colitem.config.pytestplugins.call_firstresult( |         testrep = self.colitem.config.pytestplugins.call_firstresult( | ||||||
|             "pytest_item_makereport", item=self.colitem,  |             "pytest_item_makereport", item=self.colitem,  | ||||||
|             excinfo=excinfo, when=when, outerr=outerr) |             excinfo=excinfo, when=when, outerr=outerr) | ||||||
|  | @ -69,12 +60,22 @@ class ItemRunner(RobustRun): | ||||||
|         return testrep |         return testrep | ||||||
| 
 | 
 | ||||||
| class CollectorRunner(RobustRun): | class CollectorRunner(RobustRun): | ||||||
|     def setup(self): |     def run(self): | ||||||
|         pass |         """ return result of running setup, execution, teardown procedures. """  | ||||||
|     def teardown(self): |         excinfo = None | ||||||
|         pass |         res = NORESULT | ||||||
|     def execute(self): |         capture = self.getcapture() | ||||||
|         return self.colitem._memocollect() |         try: | ||||||
|  |             try: | ||||||
|  |                 res = self.colitem._memocollect() | ||||||
|  |             finally: | ||||||
|  |                 outerr = capture.reset() | ||||||
|  |         except (Exit, KeyboardInterrupt): | ||||||
|  |             raise | ||||||
|  |         except:  | ||||||
|  |             excinfo = py.code.ExceptionInfo() | ||||||
|  |         return self.makereport(res, "execute", excinfo, outerr) | ||||||
|  | 
 | ||||||
|     def makereport(self, res, when, excinfo, outerr): |     def makereport(self, res, when, excinfo, outerr): | ||||||
|         return event.CollectionReport(self.colitem, res, excinfo, when, outerr) |         return event.CollectionReport(self.colitem, res, excinfo, when, outerr) | ||||||
|     |     | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue