在 PyDev 中使用鼻子测试进行交互式调试
我正在使用 PyDev (与 Aptana 一起)来编写和调试 Python Pylons 应用程序,并且我想在调试器中逐步完成测试。
是否可以通过 PyDev 启动鼻子测试并在断点处停止?
I'm using PyDev ( with Aptana ) to write and debug a Python Pylons app, and I'd like to step through the tests in the debugger.
Is it possible to launch nosetests through PyDev and stop at breakpoints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我使用 eclipse Pydev 运行鼻子测试的方法(希望这会对您有所帮助)。
首先,我创建一个 python 脚本,并将其放在包目录的根目录中:
在 runtest.py 中,我放入:
现在我进入菜单 Run ->;运行配置,我创建 Pydev Django 的新配置,我选择我的包并将 runtest.py 放入 主模块 中,接下来我进入参数选项卡相同的小部件,我放入程序参数我的项目的路径和不同的参数传递给脚本示例:
现在单击应用后我可以运行此配置。
为了进行调试,您可以在调试模式下运行此配置,并将断点放在代码中的任何位置,然后您可以使用出色的调试小部件执行多个操作:单步执行,查看变量...
注意:对于文档测试,遗憾的是我不这样做认为你可以将断点放在 doctest 行中,但你可以做的是将断点放在 doctest 调用的函数的 def 中,这样你就可以使用调试模式。
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 :
and in runtest.py i put:
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:
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 .
尝试导入 pydevd; pydevd.settrace() 想要一个断点。
Try
import pydevd; pydevd.settrace()
where would like a breakpoint.我在某种程度上得到了这个工作 - 也就是说,我没有断点和单步工作,但我确实让 PyDev 运行测试并在 PyUnit 视图中显示结果。
当您运行单元测试时,您必须覆盖测试运行程序以在运行配置的参数选项卡中使用“nose”和命令行参数“--with-pylons=path/to/test.ini”。例如,我将其设置为“--with-pylons=../../test.ini”。不幸的是,我必须为运行的每个测试单独设置它,我还没有找到在其中放置变量或项目路径的方法。
另外,不幸的是,我无法让断点工作。我尝试按照 http://pydev 中的建议进行修补.blogspot.ca/2007/06/why-cant-pydev-debugger-work-with.html 及其评论无济于事。 YMMV。
在 DecoratorTools-1.8-py2.7.egg/peak/util/decorators.py 中的decorate_assignment()中,将:替换
为
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:
with