Commits

Anonymous committed 37863a0

register/create methods

Comments (0)

Files changed (2)

flaskext/testing.py

             self.pop()
 
            
-class _TestModule(object):
+class TestModule(object):
 
     def __init__(self, app=None, parent=None):
 
                 
         return decorate
 
-class Testing(_TestModule):
+class Testing(TestModule):
 
     """
     Works like this::
             assert ctx.browser.status_code == 200
             assert ctx.browser.document['#A'].tag == 'dl'
             
+    
+        testing.register_module(comments)
+
+
     The "ctx" ("test context") argument is required for all test functions using
     the @with_context, @setup and @teardown decorators.
 
 
         self._app = app
 
-    def register_module(self):
-        return _TestModule(parent=self)
+    def create_module(self):
+        return TestModule(parent=self)
+
+    def register_module(self, module):
+        module._parent = self
+        module._app = self._app
 
 # old unit-test based classes, for backward compatibility
 

tests/__init__.py

     jsonify, render_template, current_app
 
 from flaskext.testing import TestCase, TwillTestCase, \
-    ContextVariableDoesNotExist, Testing, assert_404
+    ContextVariableDoesNotExist, Testing, TestModule, assert_404
 
 def create_app():
 
 def test_fixtures(ctx):
     assert ctx.fixtures.x == 10
 
-testmod = testing.register_module()
+testmod = testing.create_module()
 
 @testmod.setup
 def set_y(ctx):
     assert ctx.fixtures.x == 10
     assert ctx.fixtures.y == 20
 
+
 def test_make_fail():
     @testmod.with_context
     def do_fail(ctx):
     except AssertionError:
         pass
 
-testmod2 = testing.register_module()
+testmod2 = testing.create_module()
 
 @testmod2.setup
 def set_z(ctx):
 
 value = 5
 
-increments = testing.register_module()
+increments = testing.create_module()
 
 @increments.setup
 def increment(ctx):
     assert value == 5
 
 
+testmod3 = TestModule()
+
+@testmod3.setup
+def create_data(ctx):
+    ctx.fixtures.x = 10
+
+@testmod3.with_context
+def test_x(ctx):
+    assert ctx.fixtures.x == 10
+
+testing.register_module(testmod3)
+
 class TestSetup(TestCase):
 
     def create_app(self):