changeset 176:429ca1c60a1f

py.test conftest fixes, details see below, updated copyright init_test_app / deinit_test_app: removed the calls on class level this should not be needed as we call them with setup_method and teardown_method and we don't have support for nesting these calls. init_test_app on module level: removed, for similar reasons. I checked the tests with and without this and we seem to no need init_test_app on module level. There was no call to deinit_test_app on module level btw. In case we ever need this, we could maybe do it on function level (not module level) using setup_function and teardown_function. teardown_method: changed order of calls: we need to first call the wrapped classes' teardown_method and afterwards deinit the test app. Otherwise it crashes if the classes' teardown_method uses stuff removed by deinit.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 10 Apr 2011 19:42:34 +0200
parents d3b415b65562
children 9cc75ad9d6d1
files MoinMoin/conftest.py
diffstat 1 files changed, 7 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/conftest.py	Sun Apr 10 18:22:57 2011 +0200
+++ b/MoinMoin/conftest.py	Sun Apr 10 19:42:34 2011 +0200
@@ -1,6 +1,6 @@
 # Copyright: 2005 MoinMoin:NirSoffer
 # Copyright: 2007 MoinMoin:AlexanderSchremmer
-# Copyright: 2008 MoinMoin:ThomasWaldmann
+# Copyright: 2008,2011 MoinMoin:ThomasWaldmann
 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
 
 """
@@ -91,10 +91,10 @@
             given_config = cls.Config
         else:
             given_config = wikiconfig.Config
-        cls.app, cls.ctx = init_test_app(given_config)
 
         def setup_method(f):
             def wrapper(self, *args, **kwargs):
+                # Important: FIRST init the test app, then call the wrapped function.
                 self.app, self.ctx = init_test_app(given_config)
                 # Don't forget to call the class' setup_method if it has one.
                 return f(self, *args, **kwargs)
@@ -102,9 +102,12 @@
 
         def teardown_method(f):
             def wrapper(self, *args, **kwargs):
+                # Don't forget to call the class' teardown_method if it has one.
+                # Important: FIRST call the wrapped function, so it can still
+                # access the stuff removed by deinit_test_app:
+                ret = f(self, *args, **kwargs)
                 deinit_test_app(self.ctx)
-                # Don't forget to call the class' teardown_method if it has one.
-                return f(self, *args, **kwargs)
+                return ret
             return wrapper
 
         try:
@@ -128,20 +131,12 @@
         super(MoinClassCollector, self).setup()
 
     def teardown(self):
-        cls = self.obj
-        deinit_test_app(cls.ctx)
         super(MoinClassCollector, self).teardown()
 
 
 class Module(py.test.collect.Module):
     Class = MoinClassCollector
 
-    def __init__(self, *args, **kwargs):
-        given_config = wikiconfig.Config
-        self.app, self.ctx = init_test_app(given_config)
-        # XXX do ctx.pop() in ... (where?)
-        super(Module, self).__init__(*args, **kwargs)
-
     def run(self, *args, **kwargs):
         if coverage is not None:
             coverage_modules.update(getattr(self.obj, 'coverage_modules', []))