Python 在Nose中运行与unittest子类无关的单个测试函数
Python 在Nose中运行与unittest子类无关的单个测试函数,python,nose,Python,Nose,nose发现以test\uu开头的测试,以及unittest.TestCase的子类 如果希望运行单个TestCase测试,例如: # file tests.py class T(unittest.TestCase): def test_something(): 1/0 这可以通过以下命令行完成: nosetests tests:T.test_something 有时我更喜欢编写一个简单的函数并跳过所有unittest样板文件: def test_something_
nose
发现以test\uu
开头的测试,以及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
运行。但是,我如何告诉nose
使用(Unix)命令行仅运行该测试呢?这将是:
nosetests tests:test_something_else
另一个技巧是使用属性
from nose.plugins.attrib import attr
@attr('now')
def test_something_else():
pass
要运行使用该属性标记的所有测试,请执行:
nosetests -a now
相反,避免运行这些测试:
nosetests -a !now
完美的不知道为什么我在闲逛的时候没有偶然发现。谢谢