plone/plone.caching — pull request #1 by jone (2014-07-15 09:21:30+00:00)
Title: Ruleset registry testing isolation

Belongs to plone/Products.CMFPlone/issues/223

Most unit test in `plone.caching` rely on the fact they are run before all the Plone ZCML is loaded.
They rely on not having the `z3c.caching` ruleset registry in explicit mode.

**Problem**
The ruleset registry's explicit mode forces all rules to be registered as rule utility in the component registry, but the tests do not register any utilities. When the tests are run before integration tests this works well, but when the tests are run after integration tests the isolation is broken and results in errors such as:

```python
Error in test test_operation_name_not_found (plone.caching.tests.test_hooks.TestMutateResponseStreaming)
Traceback (most recent call last):
File "/Users/jone/projects/python/buildout.python/parts/opt/lib/python2.7/unittest/case.py", line 327, in run
testMethod()
File "/Users/jone/projects/python/cache/eggs/plone.caching-1.0-py2.7.egg/plone/caching/tests/test_hooks.py", line 512, in test_operation_name_not_found
z3c.caching.registry.register(DummyView, 'testrule')
File "/Users/jone/projects/python/cache/eggs/z3c.caching-2.0a1-py2.7.egg/z3c/caching/registry.py", line 144, in register
return registry.register(obj, rule)
File "/Users/jone/projects/python/cache/eggs/z3c.caching-2.0a1-py2.7.egg/z3c/caching/registry.py", line 64, in register
raise LookupError("Explicit mode set and ruleset %s not found" % rule)
LookupError: Explicit mode set and ruleset testrule not found
```

The `plone.app.caching` [ZCML load hook](https://github.com/plone/plone.app.caching/blob/master/plone/app/caching/setuphandlers.py#L3) sets the ruleset registry into explicit mode, which is one of the sources of the isolation problem.

**Solution**
The proposed solution is to use a unit testing layer which makes sure that the ruleset registry is not in explicit mode.
This makes the tests order independent and thus fixes isolation problems.

**Background**
As discussed in plone/Products.CMFPlone/issues/223 adding packages with PloneTestCases (such as plone.app.versioningbehavior) to the same testing group results in a different testing order and the unit tests are no longer run before loading ZCML.

/cc @tisto