【问题标题】:Tox Not Respecting Defined envlist in Custom EnvironmentsTox 不尊重自定义环境中定义的 envlist
【发布时间】:2021-10-13 18:08:34
【问题描述】:

鉴于以下 tox.ini 文件:

[tox]
envlist = py39
isolated_build = True
requires =
    tox-poetry-dev-dependencies

[testenv]
description = Default environment
commands =
    python --version

[testenv:mytestenvironment]
commands =
    python --version

我期望$ tox -r$ tox -r -e mytestenvironment 都产生Python 3.9.7,但是,后面的语句产生Python 3.10.0。我的本地环境,通过$ python3 --version确认默认环境为3.9.7;我相信3.10.0是从brew upgrade引入的(显然是最新的tox3.24.4需要Python >=3.10.0

问题是:如何修改 tox.ini 以强制使用 Python 3.9

【问题讨论】:

    标签: python continuous-integration tox


    【解决方案1】:

    您想在 testenv 中使用 basepython ? envlist 只是默认目标环境,而不是环境配置。

    【讨论】:

      【解决方案2】:

      为了后代,以下解决了问题(c/o @Yeti

      [tox]
      envlist = py39
      isolated_build = True
      requires =
          tox-poetry-dev-dependencies
      
      [testenv]
      description = Default environment
      basepython = python3.9
      commands =
          python --version
      
      [testenv:mytestenvironment]
      commands =
          python --version
      

      文档:Tox Configuration Specification::Tox Environment Settings::basepython

      您可以放入testenv* 部分的完整设置列表:

      ...

      basepython(NAME-OR-PATH)

      将用于创建虚拟环境的 Python 解释器的名称或路径,这实际上决定了我们将创建虚拟隔离环境的 Python。使用它来指定 tox 环境的 python 版本。如果未指定,虚拟环境因素(例如名称部分)将用于自动设置一个。例如,py37 表示python3.7py3 表示python3py 表示python。 provision_tox_env 环境不会从 toxenv 部分继承此设置。

      ...

      此外,[testenv] 部分是其他任何没有从文档中轻松了解的人的“父级”。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-16
        • 1970-01-01
        • 2011-02-21
        • 1970-01-01
        • 1970-01-01
        • 2015-10-06
        • 2011-03-18
        • 2018-07-06
        相关资源
        最近更新 更多