-
Notifications
You must be signed in to change notification settings - Fork 0
Using Eclipse with autotest
-
Download latest Eclipse (doesn't matter which version, there is no existing stock version with python) http://download.eclipse.org/eclipse/downloads/
-
Use any folder as default workspace path (it's basically a name, you can have sources anywhere else)
-
Select Help->Install new software and Add new source and install current version of PyDev for Eclipse
Name: pydev Location: http://pydev.org/updates
- 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
-
After Eclipse restart right-click in Navigator window and select
Import...
,Git->Projects from Git
, add Autotest base directory and on next window checkImport as general project
. -
From now one, you can start developing Autotest. Anyway I'd recommend you to go through next section first ;-)
- 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
-
than you add this directory to python path in
right-click on project
->properties
->PyDev - PYTHONPATH
->External Libraries
clickAdd source folder
and find the$somedir
directory. -
From now one you'll see docstrings and all the other usual features of Eclipse.
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.
I'd recommend you to turn on line numbers (Window
->Preferences
->General
->Editors
->Text Editors
->Show line numbers
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...
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.
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:
- Add
breakpoint
into the script (special one, of course) - Start PyDev
Debug Server
- Execute the code anywhere (even on remote computer)
- 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.
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)