changeset 571:957d41c088db pytest2

added 'try', 'finally' in MoinTestFunction
author pkumar <contactprashantat@gmail.com>
date Sun, 05 Jun 2011 03:00:16 +0530
parents 964a9744310c
children 81f27ab8c620
files MoinMoin/conftest.py
diffstat 1 files changed, 20 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/conftest.py	Wed Jun 01 19:16:42 2011 +0530
+++ b/MoinMoin/conftest.py	Sun Jun 05 03:00:16 2011 +0530
@@ -29,7 +29,7 @@
 import inspect
 
 import pytest
-
+import py
 from MoinMoin.app import create_app_ext, destroy_app, before_wiki, after_wiki
 from MoinMoin._tests import maketestwiki, wikiconfig
 from MoinMoin.storage.backends import create_simple_mapping
@@ -58,27 +58,27 @@
 
 
 class MoinTestFunction(pytest.collect.Function):
-    def setup(self):
-        if inspect.isclass(self.parent.obj.__class__):
-            cls = self.parent.obj.__class__
-        if hasattr(cls, 'Config'):
-            given_config = cls.Config
-        else:
-            given_config = wikiconfig.Config
-        
-        self.app, self.ctx = init_test_app(given_config)
+    try:
+        def setup(self):
+            if inspect.isclass(self.parent.obj.__class__):
+                cls = self.parent.obj.__class__
+            if hasattr(cls, 'Config'):
+                given_config = cls.Config
+            else:
+                given_config = wikiconfig.Config
+            
+            #pytest.set_trace()
+            self.app, self.ctx = init_test_app(given_config)
+            super(MoinTestFunction, self).setup()
+            #XXX: hack till we get better funcarg tools
+            if hasattr(self._obj, 'im_self'):
+                self._obj.im_self.app = self.app
 
-        super(MoinTestFunction, self).setup()
-        #XXX: hack till we get better funcarg tools
-        if hasattr(self._obj, 'im_self'):
-            self._obj.im_self.app = self.app
+    finally:
+        def teardown(self):
+            super(MoinTestFunction, self).teardown()
+            deinit_test_app(self.app, self.ctx)        
 
-    def teardown(self):
-        super(MoinTestFunction, self).teardown()
-        deinit_test_app(self.app, self.ctx)
-        
-
-    
     # Need to modify and add more stuffs