Dear all,

I'm not sure if this is the expected behaviour or not. In the documentation 
it states that DummyRequests implement add_finished_callback.

http://docs.pylonsproject.org/projects/pyramid/en/latest/whatsnew-1.2.html

However, to me it seems like the added callbacks never get called when I 
run the tests.

What I did.

1. Created a new "starter" project using pcreate
2. Modified the __init__.py file to include the lines

from pyramid.events import NewRequest
from pyramid.events import subscriber

@subscriber(NewRequest)
def new_request_subscriber(event):
    print 'In new request subscriber...'
    request = event.request
    print 'Request: %s' % request
    request.add_finished_callback(finished_callback)

def finished_callback(request):
    print 'In finished_callback...'

3. Modified the test_my_view function in the tests.py file 

    def test_my_view(self):
        from .views import my_view
        from pyramid.events import NewRequest
        from test_pyramid import new_request_subscriber
        request = testing.DummyRequest()
        
        self.config.testing_add_subscriber(NewRequest)
        event = NewRequest(request)
        self.config.registry.notify(new_request_subscriber(event))

        info = my_view(request)
        self.assertEqual(info['project'], 'test_pyramid')

4. Ran the tests (python setup.py test -q)

In new request subscriber...
Request: <pyramid.testing.DummyRequest object at 0x8f60a2c>
.
----------------------------------------------------------------------
Ran 1 test in 0.008s

OK

Note that in the above the finished_callback was never triggered.

This is a silly example, but the problem is that in my real application I 
need the test code to be able to close a handle to a database that I have 
opened using the new_request_subscriber.

Any ideas how I can get the finished_callback to be triggered?




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


Reply via email to