History for FrequentlyAskedQuestions
??changed:- <hr> Why is <your favourite REQUEST variable here> missing from the REQUEST? ZTC only has a very minimal REQUEST. If you need anything fancy in the REQUEST (like SESSION, PARENTS, URL1, ...) you will have to put it there yourself, typically in afterSetUp. See e.g. testShoppingCart.py. <hr> How do I enable the Zope event log? To enable the event log you have to set the required environment variables before importing '!ZopeTestCase'. Your 'test*.py' file should begin with something like:: os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log') os.environ['EVENT_LOG_SEVERITY'] = '-300' from Testing import ZopeTestCase <hr> How do I test an existing ZODB? Create a 'custom_zodb.py' file in your 'tests' directory that looks like the following:: import os from ZODB.DemoStorage import DemoStorage from ZODB.FileStorage import FileStorage db = os.path.join('..', '..', '..', 'var', 'Data.fs') db = os.path.abspath(db) Storage = DemoStorage(base=FileStorage(db, read_only=1)) This way your test !DemoStorage will be based on the existing !FileStorage. You may safely play around in the !DemoStorage without having to fear corruption of the base db. <hr> How do I attach to a running ZEO server? 1. Setup a ZEO server and start it. 2. Setup a Zope instance as ZEO client. The instance directory must contain a 'custom_zodb.py' file. 3. Set the 'ZEO_INSTANCE_HOME' environment variable to point to the instance directory. 4. Run the tests by typing 'python testBlahBlah.py' or 'python runalltests.py'. !ZopeTestCase will then use the instance's 'custom_zodb.py' to connect to the ZEO server instead of setting up the test !DemoStorage. Alternatively, you can add the 'custom_zodb.py' file to the 'tests' directory along the lines of the previous example, and skip steps 2 and 3. Background information is available here: ZopeEnvironment <hr> Why does cut/copy/paste/clone/rename give !CopyErrors? Should you have problems with these operations make sure a '_p_jar' is set up by performing a subtransaction commit:: get_transaction().commit(1) I found this documented in the sources of 'OFS/CopySupport.py', see method '_getCopy()'. <blockquote> Simon Michael reports this hint did not work for him, and he had to resort to a hack and set 'ZwikiPage.cb_isMoveable = lambda x:1'. I plan to look into this. </blockquote> <hr> Why does import/export give !AttributeErrors? You may see '"None object has no attribute ..."' errors when trying to import or export a Zope object. Should you see such errors make sure a '_p_jar' is set up by performing a subtransaction commit like above. <hr> Is it allowed to explicitly commit a transaction in a test? While it is allowed to commit a **subtransaction** as hinted above, committing a full (complete?) transaction is generally **not recommended**. Transactions are supposed to be handled transparently by !ZopeTestCase, and you have to be careful to cleanup your own mess once you call 'get_transaction().commit()' inside of 'afterSetUp' or a test method. The 'testWebserver.py' example shows how one might go about committing manually, but you will rarely want to do so - honest. <hr>