Skip to content

HOW TO Debug and test Plomino applications

Eric BREHAULT edited this page Sep 21, 2016 · 1 revision

How to find why a formula is not working as expected.

Plomino debug mode

In Plomino, there is a debug mode (go to db, edit, then check Debug mode), it just enables a verbose mode, so you get more information in the Zope server log.

Plone debug practices

You can use all the Plone dev tools and good practices:

##Traces in the log You can add some traces like this:

Log("My value is:"+plominoDocument.the_value)

it will be displayed in the Zope log.

##Zope in debug mode You can launch your Zope instance in debug mode (non HTTP):

bin/instance debug

you get a python prompt where 'app' is the Zope application (so app.Plone.yourdb will be your db object).

ZDB

Install zdb (see https://secure.simplistix.co.uk/svn/Simplistix/zdb/trunk/readme.txt), then insert this line in any Plomino formula:

from Products.zdb import set_trace; set_trace()

and when the formula is executed, you will be in debug mode in your server console.

Note: ZDB is an old product, but it does work, and is very useful.

Testing

You can create some Selenium tests to validate a behaviour and make sure it is not impacted by further changes.

You can create some python doctests (you can export your Plomino db as xml and have a doctest able to import it automatically in a blank site and run some tests, example: https://plomino.svn.sourceforge.net/svnroot/plomino/trunk/Plomino/Products/CMFPlomino/tests/samples.txt (that is what we use in our buildbot to run the Plomino continuous testing).

Python introspection

In Python you can do:

>>> dir(obj)

it returns all the object methods (which can be a bit much for Plone objects with deep inheritance trees);

>>> obj.__dict__

it returns all the attributes as a dictionary;

>>> obj.__class__

it returns the class;

>>> hasattr(obj, "something")

tests if the object has an attribute or method named "something" ("something" may be found via acquisition; if you don't want acquisition, use shasattr from Products/Archetypes/utils.py).