nose
发现以 test_
开头的测试,以及 unittest.TestCase
的子类。
如果希望运行单个 TestCase
测试,例如:
# file tests.py
class T(unittest.TestCase):
def test_something():
1/0
这可以在命令行上完成:
nosetests tests:T.test_something
我有时更喜欢编写一个简单的函数并跳过所有unittest
样板:
def test_something_else():
assert False
在这种情况下,当运行我的所有测试时,测试仍将由 nose
运行。但是我如何使用 (Unix) 命令行告诉 nose
仅运行该测试?
最佳答案
那就是:
nosetests tests:test_something_else
另一个技巧是使用属性
from nose.plugins.attrib import attr
@attr('now')
def test_something_else():
pass
要运行用该属性标记的所有测试,请执行:
nosetests -a now
相反,避免运行这些测试:
nosetests -a !now
关于python - 在 Nose 中运行与单元测试子类无关的单个测试函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15282503/