python - 将 paver 和 nose 与非典型目录结构一起使用

标签 python nose paver

我正在尝试为 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.pyfile6.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/

相关文章:

python - 如何使用字典更改另一个 pandas 列

python - 将配置文件模型连接到远程用户(自定义身份验证后端)

python - 如何通过 python-docx 将列表项目符号中的某些单词加粗

python - nose 中有 self.assertNotEqual() 的快捷方式吗?

django - 使用 Nose 运行单元测试时出现 South 错误

python-2.7 - 在 PyCharm 中使用并排安装了 python 2 和 3 的 Nose 测试

python - 将python摊铺机安装到ubuntu

python - 如何使用 Pandas 和 tabula-py 从一个 PDF 文件中提取多个表格