gpt4 book ai didi

python - 禁用 Python Nose 测试

转载 作者:IT老高 更新时间:2023-10-28 20:31:06 26 4
gpt4 key购买 nike

当使用 Python 的 Nose 测试时,可以通过将测试函数的 __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 输出中。是否有另一种构造装饰器的方法,以便测试不会运行并且不会出现在 Nose 测试输出中。

最佳答案

Nose 已经为此内置了一个装饰器:

from nose.tools import nottest

@nottest
def test_my_sample_test()
#code here ...

还可以查看 Nose 提供的其他好东西:https://nose.readthedocs.org/en/latest/testing_tools.html

关于python - 禁用 Python Nose 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1120148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com