运行生成的鼻子测试
假设我定义了一个 testFile.py python 模块,如下所示。
def test_evens():
for i in range(0, 5):
yield check_even, i, i*3
def check_even(n, nn):
assert n % 2 == 0 or nn % 2 == 0
当我让鼻子识别仅收集模式下的测试时,我发现
testFile.test_evens(0, 0) ... ok
testFile.test_evens(1, 3) ... ok
testFile.test_evens(2, 6) ... ok
testFile.test_evens(3, 9) ... ok
testFile.test_evens(4, 12) ... ok
我可以使用以下命令运行所有测试
nosetests -v testFile:test_evens
但是,如果我只想运行 testFile.test_evens(2, 6) (即不是所有测试)怎么办?
有什么方法可以从命令行执行此操作吗?
Suppose I define a testFile.py
python module with as follows.
def test_evens():
for i in range(0, 5):
yield check_even, i, i*3
def check_even(n, nn):
assert n % 2 == 0 or nn % 2 == 0
When I let the nose identify the tests in collect-only mode I get
testFile.test_evens(0, 0) ... ok
testFile.test_evens(1, 3) ... ok
testFile.test_evens(2, 6) ... ok
testFile.test_evens(3, 9) ... ok
testFile.test_evens(4, 12) ... ok
I can run all tests using
nosetests -v testFile:test_evens
However, what if I only want to run testFile.test_evens(2, 6) (i.e., not all the tests)?
Is there any way to do this from the command line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,鼻子默认无法做到这一点。以下是一些选项:
1。从命令行伪造它
可能不是您正在寻找的,但我不得不提一下。你也可以
创建一个包装脚本来简化此操作:
2.创建自定义鼻子测试加载器
这有点复杂,但您可以创建自定义测试
加载器将命令行参数解释为指定生成器
加载,从生成器中提取测试和参数,并返回包含具有匹配参数的测试的套件。
下面是一些示例代码,应该足以让您构建(runner.py):
执行它:
Nose cannot do this by default, to my knowledge. Here are some options:
1. Fake it from the command line
Probably not what you're looking for, but I had to mention it. You could also
create a wrapper script to simplify this:
2. Create a custom nose test loader
This is a little more involved, but you can create a custom test
loader which interprets the command-line arguments as specifying the generator
to load, pulls out tests and arguments from the generator, and returns a suite containing the test(s) with the matching arguments.
Below is some example code which should give you enough to build on (runner.py):
Executing it: