[Zope3-dev] Bug in functional doctest suite?

Maciej Wisniowski maciej.wisniowski at coig.katowice.pl
Tue May 1 17:52:14 EDT 2007


Hi

I was trying to write test to expose bug with
Retry exception and views and I used functional
doctests for this.

I found that in zope/app/testing/functional.py
there is a class HTTPCaller with __call__ method like:

class HTTPCaller(CookieHandler):
    """Execute an HTTP request string via the publisher"""

    def __call__(self, request_string, handle_errors=True, form=None):
        (...)
        response = ResponseWrapper(
            request.response, path,
            omit=('x-content-type-warning', 'x-powered-by'),
            )

        publish(request, handle_errors=handle_errors)
        self.saveCookies(response)
        setSite(old_site)

        # sync Python connection:
        getRootFolder()._p_jar.sync()

        return response

I was dealing with Retry exception and I get
strange errors during test. I found it is because
__call__ method assumes that request and response
are same objects during whole function.
It is not true when Retry exception is raised by
published code because retry creates new request
and response objects.
I think above code should be changed to:

class HTTPCaller(CookieHandler):
    """Execute an HTTP request string via the publisher"""

    def __call__(self, request_string, handle_errors=True, form=None):
        (...)
        request = publish(request, handle_errors=handle_errors)

        response = ResponseWrapper(
            request.response, path,
            omit=('x-content-type-warning', 'x-powered-by'),
            )

        self.saveCookies(response)
        setSite(old_site)

        # sync Python connection:
        getRootFolder()._p_jar.sync()

        return response

Any opinions? I can say that only with this change my tests for Retry
exception are working as they should.

I think tomorrow I'll be able to submit this and another bug reports
to the collector (another bug is one with Retry and views) because
at last I think I've written test that exposes both of these bugs.


More information about the Zope3-dev mailing list