如何在 Buildout 中对我的 Python 代码进行 运行 单元测试?

How do I run unit tests on my Python code in Buildout?

我有一个 Python 项目,由 zc.buildout 管理。

我的 buildout.cfg 文件如下所示:

[buildout]
parts = python ipython
develop = .
eggs = redditsubscraper
versions = versions

[versions]

[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}

[ipython]
recipe = zc.recipe.egg:scripts
eggs = ${buildout:eggs}
    ipython
scripts = ipython

我想为我的库中的 运行ning 单元测试添加一个 bin/test 脚本。

如何添加这个脚本?是否有我需要的方法可以让我 运行 bin/test 并进行单元测试 运行?

我找到了方法。

buildout.cfg 添加新部分:

[test]
recipe = pbp.recipe.noserunner
eggs = ${buildout:eggs}
    pbp.recipe.noserunner
script = test

将该部分添加到您的 buildout:parts:

[buildout]
parts = python ipython test
# ...

运行 bin/buildout 你会在 bin/ 文件夹中得到一个名为 test 的脚本。 运行 该脚本 运行 您项目中的所有测试。