On Jul 3, 2010, at 6:57 AM, Hans Lellelid wrote:

> But obviously the better approach would be to keep the changes in the
> code I control :)

This is exactly the approach I'm taking to fix testing up for Pylons 1.1. Here 
is what the tests/__init__.py looks like in the 1.1 branch for example (which 
will work fine for projects right now using Pylons):
"""Pylons application test package

This package assumes the Pylons environment is already loaded, such as
when this script is imported from the `nosetests --with-pylons=test.ini`
command.

This module initializes the application via ``websetup`` (`paster
setup-app`) and provides the base testing objects.
"""
from unittest import TestCase
import os
import sys

import pylons
from pylons.i18n.translation import _get_translator
from paste.deploy import loadapp
from pylons import url
from routes.util import URLGenerator
from webtest import TestApp

from {{package}}.config.environment import load_environment

__all__ = ['environ', 'url', 'TestController']

environ = {}
here_dir = os.path.dirname(os.path.abspath(__file__))
conf_dir = os.path.dirname(os.path.dirname(here_dir))

sys.path.insert(0, conf_dir)


class TestController(TestCase):
    def __init__(self, *args, **kwargs):
        wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
        config = wsgiapp.config
        pylons.app_globals._push_object(config['pylons.app_globals'])
        pylons.config._push_object(config)
        
        # Initialize a translator for tests that utilize i18n
        translator = _get_translator(pylons.config.get('lang'))
        pylons.translator._push_object(translator)
        
        url._push_object(URLGenerator(config['routes.map'], environ))
        self.app = TestApp(wsgiapp)
        TestCase.__init__(self, *args, **kwargs)


Replace {{package}} with the name of your project. Note that this sets up the 
following globals:
config, app_globals, url, and translator (needed for set_lang/get_lang/i18n)

Using this, you should be able to remove the 'with-pylons' line from the 
setup.cfg, as the plugin shouldn't be needed (unless you're doing doc testing 
of your project...).

Making testing great is definitely a top priority for Pylons, and some of the 
other new stuff coming in 1.1 will lead to substantially easier unit testing in 
addition to the functional/integrated testing Pylons emphasizes with the usage 
of TestApp.

Cheers,
Ben

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to