AttributeError: test_user_1_

by Mikko Ohtamaa last modified Dec 30, 2008 03:08 PM
Unit tests fail when trying create content using invokeFactory() on Plone 2.5.1/Zope 2.9.4

Explanation

 

When executing unit tests directly instead of through zopectl, Plone 2.5.1/Zope 2.9.4 fails to set-up unit tests propeply. This is notable, since Windows users cannot run zopectl.

 

See Zope Collector #2178

.

 

Also, about debugging layers

.

 

See also Running unit tests on Windows?

thread on plone.dev mailing list.

 

Workaround

From Sidnei da Silva

On Thu, Oct 26, 2006 at 04:40:12PM -0700, Andy McKay wrote:
| Apparently unit tests can no longer be run using anything other  
| zopectl for Plone 2.5.1, doing so gives you AttributeErrors on  
| test_user_1_ (according to Alec). So if that's the case how do you  
| run them on Windows?

Something like this, I call mine test.bat:

@set ZOPE_HOME=C:\src\dev\Zope-2.9-bin
@set INSTANCE_HOME=c:\src\dev\instance\es30
@set PYTHON=c:\python24\python.exe
@set SOFTWARE_HOME=%ZOPE_HOME%\lib\python
@set CONFIG_FILE=%INSTANCE_HOME%\etc\zope.conf
@set PYTHONPATH=%SOFTWARE_HOME%
@set TEST_RUN=%ZOPE_HOME%\bin\test.py

"%PYTHON%" "%TEST_RUN%" --config-file="%CONFIG_FILE%" --usecompiled -vp %1 %2 %3 %4 %5 %6 %7

I can add that to the Plone Windows Installer.

Fix

Here is my test.bat

@echo off

REM Invoking unit test directly doesn't work anymore on Plone 2.5.1
REM See http://plone.org/documentation/error/attributeerror-test_user_1_

REM @set ZOPE_HOME=C:\src\dev\Zope-2.9-bin
set PYTHON=d:\python24\python.exe
set ZOPE_HOME=F:\workspace\plone-2.5.1\Zope-2.9.6\Zope
set INSTANCE_HOME=F:/workspace/plone-2.5.1/instance
set SOFTWARE_HOME=%ZOPE_HOME%\lib\python
set CONFIG_FILE=%INSTANCE_HOME%\etc\zope.conf
set PYTHONPATH=%SOFTWARE_HOME%
set TEST_RUN=%ZOPE_HOME%\bin\test.py

rem "%PYTHON%" "%TEST_RUN%" --config-file="%CONFIG_FILE%" --usecompiled -vp %1 %2 %3 %4 %5 %6 %7
"%PYTHON%" "%TEST_RUN%" --config-file="%CONFIG_FILE%" --usecompiled -vp --package-path=%INSTANCE_HOME%/Products/DataGridField Products.DataGridField

 

Sample traceback

 

Traceback (most recent call last):
  File "C:\backup\plone-2.5.1\Zope-2.9.4\lib\python\Testing\ZopeTestCase\profiler.py", line 86, in __call__
    self.setUp()
  File "C:\backup\plone-2.5.1\Zope-2.9.4\lib\python\Testing\ZopeTestCase\PortalTestCase.py", line 62, in setUp
    self.afterSetUp()
  File "C:\backup\plone-2.5.1\instance\Products\PloneFormGen\tests\testCustomScript.py", line 26, in afterSetUp
    self.folder.invokeFactory('FormFolder', 'ff1')
  File "c:\backup\plone-2.5.1\instance\Products\ATContentTypes\lib\constraintypes.py", line 292, in invokeFactory
    RESPONSE=None, *args, **kw)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\PortalFolder.py", line 408, in invokeFactory
    return pt.constructContent(type_name, self, id, RESPONSE, *args, **kw)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\TypesTool.py", line 934, in constructContent
    ob = info.constructInstance(container, id, *args, **kw)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\TypesTool.py", line 343, in constructInstance
    ob = self._constructInstance(container, id, *args, **kw)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\TypesTool.py", line 574, in _constructInstance
    newid = m(id, *args, **kw)
  File "<string>", line 6, in addFormFolder
  File "C:\backup\plone-2.5.1\instance\Products\PloneFormGen\content\form.py", line 513, in initializeArchetype
    self.invokeFactory('FormMailerAdapter','mailer')
  File "c:\backup\plone-2.5.1\instance\Products\ATContentTypes\lib\constraintypes.py", line 292, in invokeFactory
    RESPONSE=None, *args, **kw)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\PortalFolder.py", line 408, in invokeFactory
    return pt.constructContent(type_name, self, id, RESPONSE, *args, **kw)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\TypesTool.py", line 934, in constructContent
    ob = info.constructInstance(container, id, *args, **kw)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\TypesTool.py", line 345, in constructInstance
    return self._finishConstruction(ob)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\TypesTool.py", line 357, in _finishConstruction
    ob.notifyWorkflowCreated()
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\CMFCatalogAware.py", line 145, in notifyWorkflowCreated
    wftool.notifyCreated(self)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\WorkflowTool.py", line 354, in notifyCreated
    self._reindexWorkflowVariables(ob)
  File "c:\backup\plone-2.5.1\instance\Products\CMFCore\WorkflowTool.py", line 699, in _reindexWorkflowVariables
    ob.reindexObjectSecurity()
  File "c:\backup\plone-2.5.1\instance\Products\Archetypes\CatalogMultiplex.py", line 63, in reindexObjectSecurity
    ob = brain._unrestrictedGetObject()
  File "C:\backup\plone-2.5.1\Zope-2.9.4\lib\python\Products\ZCatalog\CatalogBrains.py", line 52, in _unrestrictedGetObject
    return self.aq_parent.unrestrictedTraverse(self.getPath())
  File "C:\backup\plone-2.5.1\Zope-2.9.4\lib\python\OFS\Traversable.py", line 187, in unrestrictedTraverse
    next = bobo_traverse(REQUEST, name)
  File "c:\backup\plone-2.5.1\instance\Products\Archetypes\BaseObject.py", line 1124, in __bobo_traverse__
    raise AttributeError(name)
AttributeError: test_user_1_