Functional doctest snippet of the day
I was looking for an easy way to get the current browser.contents in my real browser to easy debug what is happening in my doctest.
Here is the snippet:
Updated the 01/13/2009
>>> import tempfile as tmp >>> def contents(): ... fd, fn = tmp.mkstemp(suffix=".html", prefix="testbrowser-") ... file = open(fn, 'w') ... file.write(browser.contents) ... file.close() ... print fn >>> import pdb; pdb.set_trace()
So now you can just call contents() and copy paste the file path in your real browser and see what’s happening in your tests. May it can be added to testbrowser.Browser ?
January 6, 2010 at 9:18 pm
ZopeTestCase already contains a better way, assuming you’re working in Zope 2:
from Testing.ZopeTestCase.utils import startZServer
startZServer()
Then it will print a port where you can access the same test site that the testbrowser is working with, in a real browser.
January 7, 2010 at 2:07 am
If you happen to use emacs, it’s great browse-url.el package proides a browse-url-of-region function. I’ve configured the package to use my system browser, then I just do “print browser.contents” at a Pdb prompt, highlight it, and then invoke that function and it opens in my browser (sans CSS and JS, of course).
Then there’s also Testing.ZopeTestCase.utils.startZServer:
http://maurits.vanrees.org/weblog/archive/2009/10/testing-in-plone
January 7, 2010 at 9:51 am
@davisagli
Well I have tested the “startZServer”. It opens a port on localhost but you must replay every things to be in the context of the test.
So it’s something different (something nice for sure) but not a better way to debug current test.
@merpattersonnet
I’m using eclipse + pydev + wtp.
January 13, 2010 at 1:30 pm
Interesting snippet!
Unfortunately it don’t work for me. Can you please post a full example and how to use it.
deeply grateful
Gomez
January 13, 2010 at 1:34 pm
It seems that indentation is broken. I m trying here with a pre html tag