Interactive debugging with nosetests in PyDev

故事扮演 提交于 2019-11-30 19:16:17

Here is what i do to run nosetests using eclipse Pydev (Hope this will help you).

first of all i create a python script and i put it in the root of my package directory :

--Package
    |
    | -- runtest.py
    |
    | -- ... (others modules) 

and in runtest.py i put:

import nose
nose.main()

now i go to in the menu Run -> Run configurations and i create a new configuration of Pydev Django i choose my package and put runtest.py in the main Module , next i go to arguments tab in the same widget and i put in Program arguments the path to my project and different arg to pass to the script example:

/home/me/projects/src --with-doctest  # Run doctests too

now after clicking on Apply i can run this configuration .

For debugging you can run this configuration in debug mode and put your break point anywhere in your code and you can use the terrific debug widget to do several action : step into, to see vars ...

N.B : for doctests sadly i don't think you can put breakpoint in the line of doctest but what you can do is to put your breakpoint in the def of the function that is called by the doctest and like that you can use the debug mode .

Try import pydevd; pydevd.settrace() where would like a breakpoint.

I got this working, somewhat - that is, I don't have breakpoints and stepping working but I do get PyDev to run the tests and show the results in the PyUnit view.

When you run the unit test you'll have to override the test runner to use "nose" and command line arguments "--with-pylons=path/to/test.ini" in the arguments tab of the run configuration. For example I set it to "--with-pylons=../../test.ini". Unfortunately I have to set this up separately for each test I run, I haven't found a way to put a variable or project path in there.

Also, unfortunately, I haven't been able to get breakpoints working. I tried patching as recommended in http://pydev.blogspot.ca/2007/06/why-cant-pydev-debugger-work-with.html and its comments to no avail. YMMV.

In DecoratorTools-1.8-py2.7.egg/peak/util/decorators.py in decorate_assignment(), replace:

oldtrace = [frame.f_trace]

with

oldtrace = [sys.gettrace()]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!