Simplify your testing.py

Plonistas, I have no idea why nobody uses this, but if you have a simple add-on with tests, in 90% of the cases your testing.py can be based on the PloneWithPackageLayer like so:

from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import PloneWithPackageLayer
from plone.testing import zope

import my.package


MY_PACKAGE_FIXTURE = PloneWithPackageLayer(
    bases=(PLONE_APP_CONTENTTYPES_FIXTURE,),
    name="MyPackageLayer:Fixture",
    gs_profile_id="my.package:default",
    zcml_package=my.package,
    zcml_filename="configure.zcml",
    additional_z2_products=["my.package"],
)


MY_PACKAGE_INTEGRATION_TESTING = IntegrationTesting(
    bases=(MY_PACKAGE_FIXTURE,),
    name="MyPackageLayer:IntegrationTesting",
)


MY_PACKAGE_FUNCTIONAL_TESTING = FunctionalTesting(
    bases=(MY_PACKAGE_FIXTURE,),
    name="MyPackageLayer:FunctionalTesting",
)


MY_PACKAGE_ACCEPTANCE_TESTING = FunctionalTesting(
    bases=(
        MY_PACKAGE_FIXTURE,
        REMOTE_LIBRARY_BUNDLE_FIXTURE,
        zope.WSGI_SERVER_FIXTURE,
    ),
    name="MyPackageLayer:AcceptanceTesting",
)

In my opinion this simplifies things a lot.

1 Like

Thanks. I appreciate that you advertise a feature that I contributed years ago.

Some plonistas are against it. No idea why. (Among others, a PR to use it in plonecli got rejected.)

1 Like

Might be b/c plonecli should be as extensible as possible? But in fact I dont know.

that was many years ago in bobtemplates.plone, we now have the flexibility to enhance packages and this you be a option the developer can opt-in to.
Some might not and many will, because it safes some time and is most of the time time what works fine. With core this has nothing to do. Many addon developers are never touching core code anyway. I'm fine with adding this.

for reference: use PloneWithPackageLayer, testing.zcml and testing profile by gotcha · Pull Request #54 · plone/bobtemplates.plone · GitHub

Plone Foundation Code of Conduct