[英]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.