[twill] redirects and debug output
titus at caltech.edu
Mon Mar 24 13:32:15 PDT 2008
On Mon, Mar 24, 2008 at 09:23:30AM -0500, Pam Zerbinos wrote:
-> Does anyone know if there is some way to introspect the debug output?
-> Actually, let me back up.
-> I need to write a test in which I pretend to be a Googlebot and verify that
-> I never see a redirect (response code 302). So far, there are two problems
-> with my plan:
-> 1. code(302) always throws an assertion error, even when there IS a
-> redirect, because twill doesn't run the assert until it stops getting
-> redirected, at which point I've got a 200
-> 2. I can see the 302s by flipping on debug, but I can't figure out if there
-> is some way to actually introspect the debug output without just running the
-> test manually and watching things scroll by (which defeats the purpose of an
-> automated test)
-> In my dream world, there is a secret option to make debug dump its output
-> into a dict. In my slightly less perfect dream world, there is an option to
-> make twill not follow redirects. Here in the real world, I'm at a bit of a
I'm happy to add a redirect-non-following option, especially if
confronted by a patch.
twill is already set up to write most everything --- including debug
output -- to a file handle. So you could, at worst, just add an
extension hook to replace that file handle with a StringIO object and
then retrieve text from that object.
Both would be appropriate solutions, I think. There may be something
cleaner to do, too.
More information about the twill