Skip to content

Using Eclipse with autotest

ldoktor edited this page May 31, 2012 · 4 revisions

How to develop Autotest in Eclipse

Instalation

  1. Download latest Eclipse (doesn't matter which version, there is no existing stock version with python) http://download.eclipse.org/eclipse/downloads/

  2. Use any folder as default workspace path (it's basically a name, you can have sources anywhere else)

  3. Select Help->Install new software and Add new source and install current version of PyDev for Eclipse

Name: pydev
Location: http://pydev.org/updates
  1. Select Help->Install new software and Add new source and install current version of Eclipse EGit
Name: egit
Location: http://download.eclipse.org/egit/updates
  1. After Eclipse restart right-click in Navigator window and select Import..., Git->Projects from Git, add Autotest base directory and on next window check Import as general project.

  2. From now one, you can start developing Autotest. Anyway I'd recommend you to go through next section first ;-)

Eclipse setup

Imports

  1. First autotest is importing libraries in different namespace. I've found a way to get over this using symlink.
mkdir -p $somedir/autotest
touch $somedir/__init__.py
touch $somedir/autotest/__init__.py
ln -s $autotest_root/client $somedir/autotest/client
  1. than you add this directory to python path in right-click on project->properties->PyDev - PYTHONPATH->External Libraries click Add source folder and find the $somedir directory.

  2. From now one you'll see docstrings and all the other usual features of Eclipse.

Pep8

Eclipse can automatically check quality of your code using pep8.py. In newer versions you can find it in Window->Preferences->PyDev->Editor->Code Analysis->pep8.py. By default it's turned off so just change the value to Warning and you'll see little exclamation mark by the unmatching lines.

Other setting

I'd recommend you to turn on line numbers (Window->Preferences->General->Editors->Text Editors->Show line numbers

Using Eclipse

There are some basic stuff that made me switch from VIM.

  • hoover over anything and you'll get docstring/definition/... of the context
  • ctrl+left-click and it'll transfer you to the definition
  • ctrl+1 (ctrl+shift+1) offers fix of issue under the cursor
  • when you place cursor somewhere, it highlights other occurrences of the current value/function
  • window->new editor opens the current source in another view. You will have 2 cursors, 2 highlights, 2 parts of current file
  • window->new window opens new window :-)
  • Right-click->refactor... does a lot of nice things (not that powerful as with Java thought, but still a great tool with preview)
  • drag and drop layouts (split view, hide consoles ... just click and move everything everywhere)
  • DEBUGING (see the next chapter)

I'm not using Eclipse for Autotest execution (although it can do that too) as I prefer xterm outputs...

Debugging with Eclipse

Direct debug in Eclipse

Basically you just configure what to execute in Run->Run Configurations...->Python Run... and than use either Run or Debug button. You add breakpoints by double click on line number.

Eclipse will offer you to switch to Debug perspective once you start debugging. You can change perspectives in the top-right tool menu (and add new perspectives too).

I don't like Eclipse console output, so I prefer different way of debuging autotest.

Remote debugging with Eclipse

More suitable for Autotest testing including server part is remote debugging. It's possible to set a breakpoint in code and let the script connect to Eclipse using socket and start debugging the code.

The basic workflow is:

  1. Add breakpoint into the script (special one, of course)
  2. Start PyDev Debug Server
  3. Execute the code anywhere (even on remote computer)
  4. Wait until the interpret reaches your breakpoint and connects Eclipse and start debugging

Ad1) Add breakpoint

Breakpoint have to import current version of pydev and set pydev breakpoint with the address of the computer running Eclipse Debug Server.

import sys
sys.path.append("/home/medic/.eclipse/org.eclipse.platform_4.1.0_1473617060/plugins/org.python.pydev.debug_2.4.0.2012020116/pysrc")
import pydevd
pydevd.settrace("127.0.0.1")

Where the added sys.path is path to your installed pydev plug-in and pydev.settrace() contains the address of computer running Eclipse Debug Server (don't forget to allow port 5678 in your firewall).

Ad2) Start PyDev Debug Server

You have to switch to Debug perspective. Than you will find Start Debug Server and Stop Debug Server buttons in Pydev menu.

Debugging

Eclipse offers usual IDE functionalities:

  • F5 Step Into
  • F6 Step Over
  • F7 Step Return
  • Mouse hoover over variables show their values
  • Variables list
  • Run and pause is working (you can't add breakpoints in remote debugging, but you can set the code to run and after a while you can click pause and it'll stop on the next line)
Clone this wiki locally