Skip to content

Instantly share code, notes, and snippets.

@dstanek
Forked from moschlar/test_quick.py
Created September 28, 2012 21:04
Show Gist options
  • Save dstanek/3802071 to your computer and use it in GitHub Desktop.
Save dstanek/3802071 to your computer and use it in GitHub Desktop.
Badass speedup of simple tg site tests
# -*- coding: utf-8 -*-
"""
This test module will run setUp and tearDown only *once* for all test cases in this module.
This is very convenient for users who want to just test multiple urls whether they are reachable and respond with the correct http response code.
"""
import logging
log = logging.getLogger(__name__)
from os import path
import sys
from tg import config
from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from webtest import TestApp
from tg2test.tests import teardown_db
from tg2test import model
app = None
class Test(object):
@classmethod
def setUpClass():
log.debug('Setting up module')
# Loading the application:
conf_dir = config.here
wsgiapp = loadapp('config:test.ini#main_without_authn',
relative_to=conf_dir)
global app
app = TestApp(wsgiapp)
# Setting it up:
test_file = path.join(conf_dir, 'test.ini')
cmd = SetupCommand('setup-app')
cmd.run([test_file])
@classmethod
def tearDownClass():
log.debug('Tearing down module')
model.DBSession.remove()
teardown_db()
def testSomeThing():
log.debug('Testing some thing')
app.get('/')
def testAnotherThing():
log.debug('Testing another thing')
app.get('/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment