Using Eclipse with Python

These are some notes about my experiences of using Eclipse with Python


1. Preparation

(From memory - details not confirmed)

This describes my working environment, which is based on Windows XP. (OK, that's not OS, but I have too much invested in this platform to change right now...)

Within Eclipse:

I'm currently using a directory layout that is modelled on that created by Maven 2 for Java projects:

 |   +--main/
 |   |   +--python/
 |   |   |   :
 |   |   +--resources/
 |   |   :   :
 |   |
 |   +--test/
 |       +--python/
 |       |   :
 |       +--resources/
 |       :   :

Within Eclipse, the Pydev editor provides various helpers and on-the-fly syntax error detection when editing Python code in .py files.

PyDev does provide a debugger, but I haven't used that yet. I prefer to organize my development around unit testing.

2. Unit Testing

PyDev contains a test runner facility that works in conjunction with the standard unit testing framework. (That is, standard with Python 2.3 and later, available as a library with earlier versions.) But getting the unit test runner to work can be confusing.

A reasonable approach would be to select the test suite main program and then select (Run -> Run as -> Python unit test). No dice. In this case, select (Run -> Run as -> Python run), and the unit tests results are displayed in a console window.

The built-in test runner works by selecting a directory containing the unit test modules in the package explorer window, and then selecting (Run -> Run as -> Python unit test). This causes PyDev to search source modules in this directory (and subdirectories?) for test cases - class methods having names that start with "test", assemles those into a test suite, then runs that test suite. This would seem to allow test code to be written as-needed, maybe even in the module under test, and have the Eclipse run-time seek out and run those test cases.

3. Resources

-- GrahamKlyne 2005-10-28 13:26:00

Creative Commons License
The content of this wiki is licensed under the Creative Commons Attribution-ShareAlike 2.0 England & Wales Licence.

OSS Watch is funded by the Joint Information Systems Committee (JISC) and is situated within the Research Technologies Service (RTS) of the University of Oxford.