在非典型目录结构中同时使用paver和nose
我正在尝试为 Paver
写一个任务,这个任务会对我的文件运行 nosetests
。
我的文件夹结构是这样的:
project/
file1.py
file2.py
file3.py
build/
pavement.py
subproject/
file4.py
test/
file5.py
file6.py
我想对所有的 *.py 文件运行文档测试(使用 --with_doctest
选项),而只有 project/test
文件夹下的文件(在这个例子中是 file5.py
和 file6.py
)需要被搜索测试例程。
我似乎搞不清楚该怎么做——我可以为 nose
写一个自定义插件,包含正确的文件,但我无法让 paver
在调用 nosetests
任务之前构建并安装这个插件。我也找不到办法让 paver
在命令行中把要测试的文件列表传递给 nosetests
。
有什么好的方法可以让这个工作正常进行吗?
1 个回答
2
这跟你想要的差不多吗?
from paver.easy import sh, path
__path__ = path(__file__).abspath().dirname()
@task
def setup_nose_plugin():
# ... do your plugin setup here.
@task
@needs('setup_nose_plugin')
def nosetests():
nose_options = '--with-doctest' # Put your command-line options in there
sh('nosetests %s' % nose_options,
# Your pavement.py is in a weird place, so you need to specify the working dir:
cwd=__path__.parent)
我其实不太确定怎么告诉nose去特定的文件里找东西,不过这跟命令行选项有关。
--where
可以让你指定一个目录,但我没有看到有什么方法可以说“只在这里运行文档测试,其他测试在这里”。你可能需要两次调用sh('nosetests')
来完成这些操作。