【问题标题】:Run 'python setup.py test' without running build_ext?在不运行 build_ext 的情况下运行“python setup.py test”?
【发布时间】:2016-02-07 19:16:33
【问题描述】:

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

如下所述: https://pythonhosted.org/setuptools/setuptools.html#test-build-package-and-run-a-unittest-suite::

python setup.py test

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

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

这可能吗?

【问题讨论】:

    标签: python setuptools distutils python-unittest


    【解决方案1】:

    我为此使用了一个环境变量。我的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 支持以这种方式传递环境变量)。

    【讨论】:

      猜你喜欢
      • 2015-06-11
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-04
      • 2014-12-21
      • 2013-06-20
      • 2022-08-20
      相关资源
      最近更新 更多