Skip to main content
 首页 » 编程设计

python之运行 'python setup.py test' 而不运行 build_ext

2025年05月04日31luoye11

我尝试在不运行 build_ext 的情况下运行 python setup.py test 以确保任何 C 扩展和项目元数据都是最新的?

如这里所解释的: https://pythonhosted.org/setuptools/setuptools.html#test-build-package-and-run-a-unittest-suite::

python setup.py test 

首先运行 build_ext,然后运行 ​​unittest。

我有很多东西要编译,有时我想在没有 build_ext 的情况下运行测试(我知道我没有修改编译的想法)

这可能吗?

请您参考如下方法:

我为此使用了一个环境变量。我的 setup.py 文件检查环境变量,并在需要时将 setup 函数的 ext_modules 参数设置为空列表:

# setup.py 
 
# ... 
 
if os.getenv('NO_BUILD') == 'true': 
    extensions = [] 
else: 
    extensions = [] 
 
setup( 
    # ... 
    ext_modules=extensions, 
) 

然后使用 NO_BUILD=true python setup.py 运行测试套件会跳过重新构建(假设您的 shell 支持以这种方式传递环境变量)。