plone / plone.app.testing

Testing tools for Plone-the-application
http://pypi.python.org/pypi/plone.app.testing
2 stars 7 forks source link

The PloneFixture tries to load plone.app.folder even if it is an aliased module #72

Closed ale-rt closed 3 years ago

ale-rt commented 3 years ago

I have a problem with the Plone fixture with a package that depends on plone.app.upgrade The tests fail to even start on Plone5.2/Python2.7 with this error:

  Set up plone.app.testing.layers.PloneFixture AttributeError: 'module' object has no attribute '__file__'

Running the tests with -D I can see that the problem is that the fixture tries to load plone.app.folder's zcml, which is a module alias created by plone.app.upgrade when nogopip was moved: https://github.com/plone/plone.app.upgrade/blob/30eb0fbf4e79f496be48ca597fca155648cf7d08/plone/app/upgrade/__init__.py#L161

This is an interactive debug section:

> /home/ale/.buildout/eggs27/zope.configuration-4.4.0-py2.7.egg/zope/configuration/config.py(300)path()
-> basepath = os.path.dirname(self.package.__file__)
(Pdb) self.package.__file__
*** AttributeError: 'module' object has no attribute '__file__'
(Pdb) self.package
<module 'plone.app.folder' (built-in)>
(Pdb) self.package.__dict__
{'__name__': 'plone.app.folder', '__doc__': None, 'nogopip': <module 'plone.app.folder.nogopip' (built-in)>}
(Pdb) has_attr(self.package, __file__)
*** NameError: name 'has_attr' is not defined
(Pdb) hasattr(self.package, "__file__")

Of course regular modules have a file:

(Pdb) import plone.folder
(Pdb) plone.folder.__file__
'/home/ale/.buildout/eggs27/plone.folder-3.0.3-py2.7.egg/plone/folder/__init__.pyc'

The error appears because my addon depends on plone.app.upgrade (and pulls in the alias) and because of this code that adds plone.app.folder to the list of modules to import if it is importable: https://github.com/plone/plone.app.testing/blob/690300e9a8a5e174f29aeed4ddd8eb38cf55ae2b/src/plone/app/testing/layers.py#L75-L82