AttributeError: 'module' object has no attribute 'DemoLayer'
Affects | Status | Importance | Assigned to | Milestone | ||
---|---|---|---|---|---|---|
zope.testing | Status tracked in Trunk | |||||
3.5 |
Fix Released
|
Undecided
|
Unassigned | |||
Trunk |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Running the tests of all Zope 3.4 KGS packages makes the test runner abort with
AttributeError: 'module' object has no attribute 'DemoLayer'
in layer_from_name.
I've added some diagnostics in r89123 to zope.testing trunk and in r89132 to the 3.5 branch. That tells me the module in question is z3c.skin.
layer = functional.
os.
__name__, 'ETestBrowserLa
so if you try to import z3c.etestbrowse
Reading the source code of the test runner enlightens me that this is a supported use case:
Note that a name -> layer cache is maintained by name_from_layer
to allow locating layers in cases where it would otherwise be
impossible.
This is why, if you run the z3c.etestbrowser tests in isolation, you won't see any problems. Something is clearing the _layer_name_cache in the test runner.
Further testing reveals that something to be zope.app.
Simplest fix: remember the old cache and restore it, so that run_with_options becomes reentrant. It's a bit ugly (see the patch; the try/finally statement pushes everything to the right producing a hard-to-read diff).
tags: | added: bugday20100424 |
Alternative ideas:
1. Drop the support for unreferenceable layers and get rid of the layer name cache. Then fix all the modules that currently make use of this (mis)feature.
2. Get rid of the global cache; instead use a local one and pass it around to functions that aren't methods and can't access it from self. Not doable in the 3.5 branch without a major refactoring; thankfully the trunk is refactored and this could be done there, I think.
I assume (1) will make someone unhappy, so I'm leaning towards option (2).