首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Tox InterpreterNotFound Gitlab-CI管道

Tox InterpreterNotFound Gitlab-CI管道
EN

Stack Overflow用户
提问于 2022-11-17 11:17:07
回答 2查看 38关注 0票数 0

在使用gitlab管道中的tox测试我的python包时,我需要一些帮助:

我想在多个版本上测试我的包。为此,我可以在我的tox.ini中编写以下内容

代码语言:javascript
运行
复制
[tox]
envlist = py{310, 311}

[testenv]
deps =
    -rrequirements.txt
commands =
    python -m pytest tests -s

运行命令tox在本地工作,因为我通过conda安装了多个python版本(我相信这就是原因)。

直到现在,我也一直在我的gitlab管道中测试我的包:(.gitlab-ci.yml)

代码语言:javascript
运行
复制
image: python:3.11

unit-test:
    stage: test
    script:
        - pip install tox
        - tox -r

这将导致管道失败,其中包含以下消息:

代码语言:javascript
运行
复制
ERROR:  py310: InterpreterNotFound: python3.10
  py311: commands succeeded

是否已经有了包含多个python版本的gitlab ci容器映像?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-11-17 18:28:14

这是我为我的一些项目想出的:

代码语言:javascript
运行
复制
'.review':
  before_script:
    - 'python -m pip install tox'
  script:
    - 'export TOXENV="${CI_JOB_NAME##review}"'
    - 'tox'

'review py38':
  extends: '.review'
  image: 'python:3.8'

'review py39':
  extends: '.review'
  image: 'python:3.9'

我已经有一段时间没有真正研究这个问题了,所以现在可能会有更好的解决办法。无论如何,该解决方案的优点是避免重复每个Python的script部分。“诀窍”是将TOXENV环境变量设置为类似于py38py39之类的变量,这样做是从作业名称中提取该值。

票数 1
EN

Stack Overflow用户

发布于 2022-11-17 15:31:59

一个临时、简单和易于维护的解决方案是使用以下.gitlab-ci.yml配置:

代码语言:javascript
运行
复制
image: python:latest

unit-test-3.11:
    image: python:3.11
    stage: test
    script:
        - pip install tox
        - tox -r -e py311

unit-test-3.10:
    image: python:3.10
    stage: test
    script:
        - pip install tox
        - tox -r -e py310

注意:

我相信还有一个更好的解决方案,它不需要多个映像/作业(例如,https://github.com/AntoineD/docstring-inheritance/blob/main/.github/workflows/tests.yml就不需要)。

但是,在有人在这里发布更好的解决方案之前,我会把这个标记为正确的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74474552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档