[Grok-dev] test isolation, grok droppings
Reinout van Rees
reinout at vanrees.org
Thu Oct 1 09:24:58 EDT 2009
A couple of things together got me a test error yesterday when coding with
jkolman. I'll mention it here in case someone else gets bitten.
a) I added a default allow_teardown=True option to z3c.testsetup when running
zcml layer tests. zope.app.testing's default is not to take any risks and to
run zcml layers in a separate python process. A brute-force way of saying "I
don't trust the component architecture to tear itself down completely". In
practice this teardown is no problem. The separate process means the profiler
and code coverage lose part of their data: 20% coverage for a 98% covered app
is the result, for instance.
b) The only possible problem with not running in a separate process is when
something changes modules/classes (once imported) at runtime.
c) Grokking modules and classes leaves droppings. Normally this isn't a
d) Long-standing grok problem: having a view in one module subclass from a
view in another one. Grok cannot reliably see that the superclass has a
grok.template(), so it requires you to re-specify it. At runtime, there's
actually not a problem as regular python inheritance picks up the template
e) Solution for (d): just add a bare render() method. Grok doesn't complain
at grok time about a missing template or render method. And when actually
rendering the view, the template takes precedence.
Combine a till e. Use a second test layer so that grokking happens a second
time. Grok groks the module with the bare-render-hack a second time and sees,
from the first run, that there's a template dropping. ERROR: both a template
and a render method!
I probably still missed some requirements for this bug to surface (like
probably alphabetic order of the module names).
Weird one :-)
Reinout van Rees - reinout at vanrees.org - http://reinout.vanrees.org
Software developer at http://www.thehealthagency.com
"Military engineers build missiles. Civil engineers build targets"
More information about the Grok-dev