在 PyDev 中使用鼻子测试进行交互式调试

发布于 2024-09-30 14:28:27 字数 110 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

离不开的别离 2024-10-07 14:28:27

这是我使用 eclipse Pydev 运行鼻子测试的方法(希望这会对您有所帮助)。

首先,我创建一个 python 脚本,并将其放在包目录的根目录中:

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

在 runtest.py 中,我放入:

import nose
nose.main()

现在我进入菜单 Run ->;运行配置,我创建 Pydev Django 的新配置,我选择我的包并将 runtest.py 放入 主模块 中,接下来我进入参数选项卡相同的小部件,我放入程序参数我的项目的路径和不同的参数传递给脚本示例:

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

现在单击应用后我可以运行此配置。

为了进行调试,您可以在调试模式下运行此配置,并将断点放在代码中的任何位置,然后您可以使用出色的调试小部件执行多个操作:单步执行,查看变量...

注意:对于文档测试,遗憾的是我不这样做认为你可以将断点放在 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 :

--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 .

幸福还没到 2024-10-07 14:28:27

尝试导入 pydevd; pydevd.settrace() 想要一个断点。

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

牵你手 2024-10-07 14:28:27

我在某种程度上得到了这个工作 - 也就是说,我没有断点和单步工作,但我确实让 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()中,将:替换

oldtrace = [frame.f_trace]

oldtrace = [sys.gettrace()]

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()]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文