Plone 3.0 ftest failure with published folder and anonymous access

Hanno Schlichting plone at hannosch.info
Wed Aug 22 08:22:08 UTC 2007


Maurits van Rees wrote:
> Derek Richardson, on 2007-08-22:
> 
>> Just in case, let's commit to the ZODB.
>>
>>      >>> from transaction import get
>>      >>> get().commit()
> 
> This has been deprecated and might not work anymore in 3.0.  Use:
> 
>       >>> import transaction
>       >>> transaction.commit()

While I don't really know why the original test is not working, one
remark about transactions.

Please don't do a full commit in tests unless you really need one and
know what you are doing. A savepoint:

  >>> transaction.savepoint(optimistic=True)

will write your changes to the ZODB as well, but even this should
usually not be needed as your changes will be visible in the same
transaction anyways.

The problem with full commits is that they will destroy the way
ZopeTestCase (and anything based on it like CMF/PloneTestCase) makes
sure individual tests all start with a clean environment.

What it does is this:

- First do some setup code (like creating the site, setting up a folder,
...) and do a full commit
- Start a new transaction
- Run one test
- Throw away all changes by reverting the last transaction
- Start a new transaction
- Run the next test
- Again throw away all changes by reverting the last transaction
...

When you do a full commit yourself in one of the tests all the changes
you made in that test will then be visible to all subsequent tests,
which completely breaks the assumption of tests being executed in a
clean well defined environment.

As one request in Zope is always one implicit transaction, you rarely
need to do any full commits. A savepoint is useful to write changes from
memory to the disk file when doing large amount of changes (like in
migrations) to avoid memory bloat, though.

Hanno





More information about the Product-Developers mailing list