Python 防止使用nose运行函数或文件?

Python 防止使用nose运行函数或文件?,python,testing,nose,Python,Testing,Nose,Nose将自动运行它在项目中找到的任何函数,从test.*开始。例如,如果有一个函数名为: """ test_server_setup.py sets up a pristine database to use for testing. DO NOT RUN ON PROD """ def test_server_init(): drop_all_tables() …然后,当您从项目根目录运行命令nosetests时,nose将运行它。是重命名此函数的唯一选项,还是有其他方法可以更改

Nose将自动运行它在项目中找到的任何函数,从
test.*
开始。例如,如果有一个函数名为:

"""
test_server_setup.py
sets up a pristine database to use for testing.
DO NOT RUN ON PROD
"""

def test_server_init():
    drop_all_tables()
…然后,当您从项目根目录运行命令
nosetests
时,nose将运行它。是重命名此函数的唯一选项,还是有其他方法可以更改文件,使nose忽略它?

装饰器正是您需要的:

nose.tools.nottest(func)

将函数或方法标记为非 测验

要排除nose测试发现拾取的文件或目录,请参阅:


这并没有回答帖子的标题“防止python文件使用nose运行”。。。而是演示如何阻止函数。@nmz787很好,更新了问题标题和答案。谢谢。
nottest
比现在坏掉的
skip
decorator好得多!(因为我仍然可以显式运行指定为
nottest
的类/方法,但该类/方法不会由nose自动运行)谢谢!
from nose.tools import nottest

@nottest
def test_server_init():
    drop_all_tables()