在使用gitlab管道中的tox
测试我的python包时,我需要一些帮助:
我想在多个版本上测试我的包。为此,我可以在我的tox.ini
中编写以下内容
[tox]
envlist = py{310, 311}
[testenv]
deps =
-rrequirements.txt
commands =
python -m pytest tests -s
运行命令tox
在本地工作,因为我通过conda安装了多个python版本(我相信这就是原因)。
直到现在,我也一直在我的gitlab管道中测试我的包:(.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
是否已经有了包含多个python版本的gitlab ci容器映像?
发布于 2022-11-17 18:28:14
这是我为我的一些项目想出的:
'.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
之类的变量,这样做是从作业名称中提取该值。
发布于 2022-11-17 15:31:59
一个临时、简单和易于维护的解决方案是使用以下.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就不需要)。
但是,在有人在这里发布更好的解决方案之前,我会把这个标记为正确的。
https://stackoverflow.com/questions/74474552
复制相似问题