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 忽略它?
最佳答案
nottest装饰器正是您所需要的:
nose.tools.nottest(func)
Decorator to mark a function or method as not a test
from nose.tools import nottest
@nottest
def test_server_init():
drop_all_tables()
要排除 Nose 测试发现拾取的文件或目录,请参阅:
关于python - 防止函数或文件用 Nose 运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22721998/