[英]Tox InterpreterNotFound Gitlab-CI Pipeline
我需要一些帮助来测试我的 python package 在 gitlab-ci 管道中使用tox
:
我想在多个版本上测试我的 package。 为此,我可以在我的tox.ini
中编写以下内容:
[tox]
envlist = py{310, 311}
[testenv]
deps =
-rrequirements.txt
commands =
python -m pytest tests -s
运行命令tox
在本地工作,因为我通过 conda 安装了多个 python 版本(我相信这就是原因)。
直到现在,我也一直在我的 gitlab 管道中测试我的 package:( .gitlab-ci.yml
)
image: python:3.11
unit-test:
stage: test
script:
- pip install tox
- tox -r
这会导致管道失败并显示以下消息:
ERROR: py310: InterpreterNotFound: python3.10
py311: commands succeeded
是否已经有一个 gitlab ci 容器镜像,其中包含多个 python 版本?
这是我为我的一些项目想出的:
'.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
环境变量设置为类似py38
或py39
的变量,这是通过从作业名称中提取此值来完成的。
一个临时的、简单的、易于维护的解决方案是使用以下.gitlab-ci.yml
配置:
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不需要).
但是,在有人在这里发布更好的解决方案之前,我会将其标记为正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.