nose的一个插件,可以方便地指定初始化脚本
nose-easy-init的Python项目详细描述
默认情况下启用的nose插件,它执行用户定义的 鼻采集或运行任何测试之前的初始化功能。这个 用户指定包含初始化函数的python模块, main,在环境变量中。
使用两个环境变量之一指定模块:
NOSE_INIT_MODULE=app.tests.nose_init NOSE_INIT_PATH=/path/to/my/app/tests/nose_init.py
然后,像往常一样做鼻子检查。
初始化模块示例
假设我们已经将初始化模块命名为nose_init.py,然后 保存在/path/to/my/app/tests/nose_init.py中。该文件必须包含 main函数。例如:
""" Initialization script which is imported when ``nosetests`` is run. The main function will be executed before any other application code is imported. """defmain():"""nose_easy_init will call this before each ``nosetests`` run."""setup_my_test_environment()setup_my_test_database()etc()
然后,在运行nosetests之前,将两个环境变量之一设置为 指定模块:
NOSE_INIT_MODULE=app.tests.nose_init NOSE_INIT_PATH=/path/to/my/app/tests/nose_init.py
注意,如果两个环境变量都定义了,那么文件系统路径, NOSE_INIT_PATH,将优先于NOSE_INIT_MODULE。