Skip to content

Instantly share code, notes, and snippets.

@dexterous
Forked from groner/terrain.py
Created June 22, 2011 10:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexterous/1039856 to your computer and use it in GitHub Desktop.
Save dexterous/1039856 to your computer and use it in GitHub Desktop.
Hooks for lettuce to run a test pylons app
'''Hooks for lettuce to run a test pylons app'''
from lettuce import *
from paste.fixture import TestApp
import pylons.test
from paste.deploy.loadwsgi import loadapp
from paste.script.appinstall import SetupCommand
from routes.util import URLGenerator
from os import getcwd
@before.each_scenario
def start_test_server(scenario):
'''Start a test instance of the app
Adds the following to world:
- app: The WSGI application defined in test.ini
- url: A routes url generator for the app
'''
if not hasattr(world, 'app'):
if not pylons.test.pylonsapp:
# setup-app looks here for an app before loading it, we need to
# use the same app otherwise we won't be using the same in
# memory database
pylons.test.pylonsapp = loadapp('config:test.ini', relative_to=getcwd(), global_conf={})
SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']])
config = pylons.test.pylonsapp.config
world.app = TestApp(pylons.test.pylonsapp)
world.url = URLGenerator(config['routes.map'], {})
@after.each_scenario
def stop_test_server(scenario):
if hasattr(world, 'app'):
if pylons.test.pylonsapp == world.app:
pylons.test.pylonsapp = None
del world.app
del world.url
if hasattr(world, 'response'):
del world.response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment