Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Nose中运行与unittest子类无关的单个测试函数_Python_Nose - Fatal编程技术网

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

完美的不知道为什么我在闲逛的时候没有偶然发现。谢谢