我正在尝试为 Paver
编写一个任务,它将在我的文件上运行 nosetests
。
我的目录结构是这样的:
project/
file1.py
file2.py
file3.py
build/
pavement.py
subproject/
file4.py
test/
file5.py
file6.py
Doctests(使用 --with_doctest
选项)应该在所有 *.py 文件上运行,而只有 project/test
下的文件(在这个例子中, file5.py
和 file6.py
) 应该搜索测试例程。
我似乎不知道该怎么做——我可以为 nose
编写一个包含正确文件的自定义插件,但我似乎无法获得 paver
在调用 nosetests
任务之前构建和安装它。我也找不到让 paver
将要测试的文件列表传递给命令行上的 nosetests
的方法。
让它发挥作用的最佳方法是什么?
最佳答案
这是否接近您想要达到的目标?
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
允许您指定一个目录,但我看不到“只在这里运行 doctests,在这里运行其他测试”的方法。您可能需要调用两次 sh('nosetests')
才能完成所有这些操作。
关于python - 将 paver 和 nose 与非典型目录结构一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/722992/