如何在 IronPython 中使用鼻子?

发布于 2024-09-08 21:38:51 字数 647 浏览 13 评论 0原文

我在命令行上使用“setup.py install”安装了nose,我能够运行“nosetests”,并且任何与testMatch正则表达式匹配的python文件都会被拾取,并且测试会在%python home%\Scripts目录中自动进行。现在我想让鼻子与我的 Iron Python 文件一起工作,如何在 %Iron Python home% 目录上安装鼻子?我注意到我的 Iron Python 主目录甚至没有 Scripts 文件夹。 如果我尝试使用 Iron Python 代码运行“nosetests”,它会抛出各种异常 例如。没有名为 clr 的模块。

有人用铁蟒鼻子吗?如果是,请指导我。我一整天都在为此苦苦挣扎 目前我唯一的解决方法是在我的 IronPython 代码中添加以下内容:

 import nose 
 nose.main(argv=['<arguments>'])

这是在 Iron Python 文件中使用鼻子的唯一方法吗?

如果没有其他办法的话,那么我想知道nose有的几个插件怎么用?特别是覆盖率插件?我为 python2.6 安装了它,但如何使其适用于 IronPython ?

我问的原因是因为使用 python ,只需调用命令行即​​可轻松使用插件,但使用 IronPython 我不知道如何使其工作。

I installed nose using the 'setup.py install' on the command line , I am able to run 'nosetests' and any python file matching testMatch regular expression is picked up and tests are automated in the %python home%\Scripts directory. Now I want nose to work with my iron Python files , how do I install nose on the %Iron Python home% directory ? i noticed my Iron Python Home directory does not even have a Scripts folder.
If i try running 'nosetests' with iron python code , it throws all sorts of exception
for eg. no module named clr.

Is anybody using nose with iron python ? if yes , please guide me. I have been struggling with this since an entire day,
currently my only workaround has been adding the following in my IronPython code:

 import nose 
 nose.main(argv=['<arguments>'])

is this is the only way to go about using nose in iron python files ?

if there is no other way , then I wanted to know how to use the several plugins that nose has ? especially the coverage plugin ? i installed it for python2.6 , but how to make it work for ironpython ?

The reason I am asking is because with python , it gets easy to use the plugins just by calling the command line , but with IronPython I don't know how to make it work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

我不在是我 2024-09-15 21:38:51

您的解决方案实际上是 nosetests 所做的一切

#!/usr/bin/env python

from nose import main

if __name__ == '__main__':
    main()

:需要确保将系统的 Python 库添加到路径中,以便它找到鼻子扩展:

>>>import sys
>>>sys.path.append(r'C:\Python26\lib')

并且您需要确保使用 ipy.exe 执行脚本,而不是您系统的 Python 可执行文件。

Your solution is actually all nosetests does:

#!/usr/bin/env python

from nose import main

if __name__ == '__main__':
    main()

You'll want to make sure you add your system's Python lib to the path for it to find the nose extensions:

>>>import sys
>>>sys.path.append(r'C:\Python26\lib')

And you'll need to make sure you're executing your script with ipy.exe and not your system's Python executable.

叫嚣ゝ 2024-09-15 21:38:51

我一直在尝试运行 sqlalchemy 测试套件,它使用鼻子插件。因此,如果有人尝试使用插件在 IronPython 上运行鼻子,这可能会很有用。

这在 ipy 上往往无法透明地工作,因为 setuptools 在 IronPython 上不太工作。

经过一番挖掘,我找到了用于手动注册插件的nose init.py 指令 - 本质上是导入插件类(它是nose.plugins.Plugin的子类),并将其添加到调用中主要的()。

这就是我的脚本最终的样子:

import sys, os
#import ironclad #not needed. i think.
sys.path.append(r'C:\Python26\lib')
#now load Jeff Hardys sqlite dll which is in sqlite folder (sqlite not supported on ipy)
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),'sqlite'))
import clr
clr.AddReference('IronPython.SQLite')
#load plugin
from sqlalchemy.test.noseplugin import NoseSQLAlchemy
from nose import main
if __name__ == '__main__':
    main(addplugins=[NoseSQLAlchemy()])

希望这对某人有帮助!

I've been trying to run the sqlalchemy test suite, which uses nose and a plugin. So, this may be useful if anyone is trying to run nose on ironpython with plugins.

this tends not to work transparently on ipy, because setuptools doesn't quite work on ironpython.

after a bit of diggin, i found the nose init.py instructions for registering a plugin manually - essentially, import the plugin class (which subclasses nose.plugins.Plugin), and add it to the call to main().

here's what my script ended up looking like:

import sys, os
#import ironclad #not needed. i think.
sys.path.append(r'C:\Python26\lib')
#now load Jeff Hardys sqlite dll which is in sqlite folder (sqlite not supported on ipy)
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),'sqlite'))
import clr
clr.AddReference('IronPython.SQLite')
#load plugin
from sqlalchemy.test.noseplugin import NoseSQLAlchemy
from nose import main
if __name__ == '__main__':
    main(addplugins=[NoseSQLAlchemy()])

Hope this helps someone!

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