3.8. Debugging

Tips on how to debug Plone

Whilst working on Plone, there will surely be times when you need to debug your own code, or someone else's code. Debugging Plone core is no different from debugging a third party producy, but there are some general tips you should bear in mind:

  • pdb is your friend. Put import pdb; pdb.set_trace() in your code, restart Zope, reload the page and use the debugger in your terminal. Learn how the debugger works and how to make the most of it.
  • Putting pdb sessions inside unit tests is often the most predictable way of entering a debugging session
  • If it helps, put print statements in your code and watch the output in the terminal, or put debug elements in a page template with tal:content.
  • If you need to debug a TTW Python Script, use context.plone_log("message") and watch your event.log
  • If it makes your life easier, put some debug code deep inside CMF or Archetypes or even Zope itself. You can always remove the file, run an svn up and get back to the previous state.
  • To debug visual problems, use the Mozilla DOM Inspector and the Web Developer and Firebug extensions to Firefox. These will save you hours of trial-and-error.
  • To debug JavaScript, install the Venkman Debugger for Mozilla.
  • Always remove any debug statements and run all tests before checkin! Checking in pdb statements is truly embarrassing.