On Wed, 2011-05-18 at 17:35 +0200, Wichert Akkerman wrote:
> I think I finally found the state leakage problem. What appears to be 
> happening is this:
> 
> First test A runs, and creates a Configuration() instance and does some 
> work on it, including calling config.scan(). This instance is garbage 
> collected once test A finishes. Next test B runs. This is a functional 
> test, and calls Configuration() during app setup. At this point any 
> actions that were created by the Configuration from test A are 
> re-discovered and called. And now comes the important thing: they are 
> called with the parameters setup in test A - including an old registry 
> instance!
> 
> The workaround is to always call config.commit() for any Configuration 
> instances created in a unittest to guarantee that there are no pending 
> actions.
> 
> Is there some way to prevent actions from leaking?

I'm not sure what it means for actions to leak.  The actions are kept on
an attribute of the configurator, so if the configurator dies, the
actions die too.  I don't understand how they'd survive the death of the
original configurator.

- C


> 
> Wichert.
> 
> 
> On 5/12/11 15:23 , Wichert Akkerman wrote:
> > I am running into something weird. I have a unittest that looks like this:
> >
> > def test_configure_default_authentication_policy(self):
> > from pyramid.interfaces import IAuthenticationPolicy
> > from pyramid.authentication import AuthTktAuthenticationPolicy
> > factory = self.ApplicationFactory()
> > config = factory.configure(factory.default_settings)
> > policy = config.registry.queryUtility(IAuthenticationPolicy)
> > self.assertTrue(isinstance(policy, AuthTktAuthenticationPolicy))
> > self.assertEqual(policy.cookie.http_only, True)
> >
> > This is testing part of a factory class that is responsible for creating
> > the WSGI app. That particular configure method looks like this:
> >
> > def configure(self, settings):
> > """Build the pyramid application configuration.
> >
> > :param dict settings: application settings
> > :rtype: :py:class:`pyramid.config.Configurator`
> > """
> > authentication_policy = AuthTktAuthenticationPolicy(
> > settings['authentication.secret'],
> > cookie_name=settings['authentication.cookie'],
> > include_ip=settings['authentication.include_ip'],
> > max_age=settings['authentication.lifetime'],
> > timeout=settings['authentication.lifetime'],
> > reissue_time=settings['authentication.reissue_time'],
> > http_only=True,
> > wild_domain=False)
> > config = Configurator(
> > settings=settings,
> > authentication_policy=authentication_policy)
> > config.set_renderer_globals_factory(GlobalsFactory)
> > config.add_route('siteroot', '/')
> > return config
> >
> > this test passes. I also have a browser test that tries the not-found
> > exception view:
> >
> > class FunctionalTestCase(unittest.TestCase):
> > def setUp(self):
> > from voipro.portal.run import main
> > from infrae.testbrowser.browser import Browser
> > self.app = main({})
> > self.browser = Browser(self.app)
> >
> >
> > class NotFoundFunctionalTests(FunctionalTestCase):
> > def test_invoked(self):
> > self.browser.open('http://localhost/not-found')
> > self.assertEqual(self.browser.status_code, 404)
> > self.assertTrue('The page you tried to access does not exist'
> > in self.browser.contents)
> >
> > this test also passes fine when run in isolation. However when I run all
> > tests the browser test fails: when the exception view is rendered the
> > globals factory is not called. It looks like there is some leakage from
> > test_configure_default_authentication_policy, but I don't see why.
> >
> > Wichert.
> >
> 


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

Reply via email to