Hi folks,

cc'ing Stefan 'cause it's his code :-)
but I thought it would be of interest to this list.

I've been using CMFTestCase to test my CMF tools.
But lately I've discovered that, if I follow the practice demonstrated
in CMFTestCase/testSkeleton.py, and create the CMF site once at
module level, then I have fatally polluted the environment for any
modules that may run later, e.g. other test modules.

For example, if I install CMF (1.4.8)  and one of my own Products, which
product contains this line:

# Create the CMF site once.

.... and then I run "./bin/zopectl test -v", then
I get about 25 new errors from core CMF tests like so:

ERROR: test_Image_RenameKeepsWorkflowState
Traceback (most recent call last):
  File "/zope/PaulInst2/Products/CMFDefault/tests/test_Image.py", line 65,
in setUp
  File "/zope/PaulInst2/Products/CMFDefault/Portal.py", line 339, in
    p = gen.create(self, id, create_userfolder)
  File "/zope/PaulInst2/Products/CMFDefault/Portal.py", line 309, in create
    parent._setObject(id, portal)
  File "/zope/ZopeSoftwareHome/lib/python/OFS/ObjectManager.py", line 248,
in _setObject
  File "/zope/ZopeSoftwareHome/lib/python/OFS/ObjectManager.py", line 81,
in checkValidId
    raise BadRequest, (
BadRequest: The id "cmf" is invalid - it is already in use.


This goes away if I delete my Product, so it's pretty clearly caused by my
test module leaving the CMF site around.

So, how do I clean up something that I created at module level?
And if that's not the right way to set up the site - what is?

I can't create the site in afterSetUp() because apparently getPortal()
needs to be able to find the portal already before that's called.

At one time, I naively had it set up in getPortal() but that seems
to have worked only in one product and only by bizarre coincidence as it
failed in every other product test I tried it with.
(Random assortment of BadRequest and ReadConflictErrors, I was
never able to sort it all out.) So that seems unlikely to be the Right
Thing (tm).

I'd rather not ditch CMFTestCase altogether, it has some nice
features that I find to be real time (and brain) savers.

Paul Winkler

Zope-CMF maillist  -  Zope-CMF@lists.zope.org

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to