如何在 Pylons 中使用 Nose 运行单个测试
我有一个 Pylons 1.0 应用程序,在 test/function 目录中包含一堆测试。 我得到了奇怪的测试结果,我只想运行一个测试。 鼻子文档说我应该能够在命令行中传递测试名称,但无论我做什么,我都会得到 ImportErrors
例如:
nosetests -x -s sometestname
给出:
Traceback (most recent call last):
File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11.4-py2.6.egg/nose/loader.py", line 371, in loadTestsFromName
module = resolve_name(addr.module)
File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11.4-py2.6.egg/nose/util.py", line 334, in resolve_name
module = __import__('.'.join(parts_copy))
ImportError: No module named sometestname
我得到相同的错误
nosetests -x -s appname.tests.functional.testcontroller
什么是正确的语法?
I have a Pylons 1.0 app with a bunch of tests in the test/functional directory.
I'm getting weird test results and I want to just run a single test.
The nose documentation says I should be able to pass in a test name at the command line but I get ImportErrors no matter what I do
For example:
nosetests -x -s sometestname
Gives:
Traceback (most recent call last):
File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11.4-py2.6.egg/nose/loader.py", line 371, in loadTestsFromName
module = resolve_name(addr.module)
File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11.4-py2.6.egg/nose/util.py", line 334, in resolve_name
module = __import__('.'.join(parts_copy))
ImportError: No module named sometestname
I get the same error for
nosetests -x -s appname.tests.functional.testcontroller
What is the correct syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
nosetests appname.tests.function.test_controller
应该可以工作,其中文件名为test_controller.py
。要运行特定的测试类和方法,请使用
module.path:ClassNameInFile.method_name
形式的路径,即用冒号分隔模块/文件路径和文件中的对象。module.path
是文件的相对路径(例如tests/my_tests.py:ClassNameInFile.method_name
)。nosetests appname.tests.functional.test_controller
should work, where the file is namedtest_controller.py
.To run a specific test class and method use a path of the form
module.path:ClassNameInFile.method_name
, that is, with a colon separating the module/file path and the objects within the file.module.path
is the relative path to the file (e.g.tests/my_tests.py:ClassNameInFile.method_name
).对于我使用 Nosetests 1.3.0 来说,这些变体是有效的(但请确保你的测试文件夹中有
__init__.py
):请注意模块名称和类名称之间的单个冒号。
For me using Nosetests 1.3.0 these variants are working (but make sure you have
__init__.py
in your tests folder):Note that single colon between module name and class name.
我必须添加“.py”文件扩展名,也就是说,
也许这是因为我的文件中没有任何类。
如果没有
.py
,nose 就会抱怨:虽然我在文件夹
/path_to/
中有一个__init__.py
。I have to add the ".py" file extension, that is,
Maybe this is because I don't have any classes in the file.
Without the
.py
, nose was complaining:And this although I have an
__init__.py
in the folder/path_to/
.我根据前面的答案写了这个小脚本:
I wrote this small script, based on the previous answers:
以下对我来说效果很好:
请注意,我的测试不是在课堂上进行的。测试方法位于单个文件中。
The following worked for me just well:
Note that my tests where not in a class. Test methods were in a single file.
对于nosetests
1.3.7
,您需要执行:nosetests --tests=tests.test_something.py,tests.test_something_else.py
。For nosetests
1.3.7
, you need to do:nosetests --tests=tests.test_something.py,tests.test_something_else.py
.