在为Python使用nosetest时,可以通过将测试函数的__test__属性设置为false来禁用单元测试。我已经使用以下装饰器实现了这一点:
def unit_test_disabled():
def wrapper(func):
func.__test__ = False
return func
return wrapper
@unit_test_disabled
def test_my_sample_test()
#code here ...然而,这有一个副作用,就是调用wrapper作为单元测试。包装器将始终通过,但它包含在nosetests输出中。有没有另一种构造装饰器的方法,这样测试就不会运行,也不会出现在nosetests输出中。
发布于 2009-07-13 15:57:44
我认为您还需要将您的装饰器重命名为未经过测试的东西。下面的代码只在我的第二个测试中失败,并且第一个没有出现在测试套件中。
def unit_disabled(func):
def wrapper(func):
func.__test__ = False
return func
return wrapper
@unit_disabled
def test_my_sample_test():
assert 1 <> 1
def test2_my_sample_test():
assert 1 <> 1发布于 2009-12-04 05:39:11
Nose已经有一个内置的装饰器来实现这个功能:
from nose.tools import nottest
@nottest
def test_my_sample_test()
#code here ...还可以看看nose提供的其他好东西:https://nose.readthedocs.org/en/latest/testing_tools.html
发布于 2015-02-20 22:06:07
您还可以使用unittest.skip装饰器:
import unittest
@unittest.skip("temporarily disabled")
class MyTestCase(unittest.TestCase):
...https://stackoverflow.com/questions/1120148
复制相似问题