I am writing a custom add-on that registers a resource registry bundle with a css and a js file. Everything works fine in the browser, but the trouble starts when I try to execute some doc tests. I want to test that the response contains my
<link ...rel="stylesheet" ... data-bundle="mybundle"... and my
<script ...data-bundle="mybundle" tags, and it does not. (When I load the page manually in the browser, those tags exist.)
In case you are wondering, I am doing this because later I want to put an
expression on my registered bundle so that these resources only get included on certain pages, and I want to be able to test this.
test_setup.py tests run fine, and I know my add-on is installed in the test layer.
Below is the doc test. I explicitly go to
prefs_install_products_form to check that the add-on is installed, and to
@@resourceregistry-controlpanel to check that the bundle exists, just to be sure.
Bundle Style and Script Tags Present ------------------------------------ >>> from plone.testing.zope import Browser >>> from plone.app.testing import SITE_OWNER_NAME >>> from plone.app.testing import SITE_OWNER_PASSWORD >>> app = layer['app'] >>> browser = Browser(app) >>> browser.open('http://nohost/plone/login_form') >>> browser.getControl('Login Name').value = SITE_OWNER_NAME >>> browser.getControl('Password').value = SITE_OWNER_PASSWORD >>> browser.getControl('Log in').click() Create object >>> browser.getLink('Page').click() >>> browser.getControl('Title').value = 'Front Page' >>> browser.getControl('Save').click() Go to Add-ons control panel >>> browser.open('http://nohost/plone/prefs_install_products_form') >>> browser.contents '...<input...name="uninstall_product" value="myaddon...' Go to Resource Registry control panel >>> browser.open('http://nohost/plone/@@resourceregistry-controlpanel') >>> browser.contents '...mybundle...' Check object view >>> browser.open('http://nohost/plone/front-page') >>> browser.contents '...<script ... data-bundle="mybundle...' <---- this fails
- Why does this fail in doctests?
- Is there a better way?
- How can I monitor/inspect the stdout/stderr stream from the instance that is driven by the tests, the way it would normally get written to a log file or to the console in 'fg' mode?