Skip to main content
 首页 » 编程设计

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

2025年05月04日22bhlsheji

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

我的 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 

我想添加一个 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 的脚本。运行该脚本以运行项目中的所有测试。