Gitlab CI/CD:与Conda一起运行的Pytest



上下文:我正在尝试设置一个 gitlab CI/CD,用于测试我的构建并在推送代码时运行我的 pytest 测试。

问题:当我推送代码时,CI/CD作业失败,说:

/bin/bash: line 55: pytest: command not found
ERROR: Job failed: exit code 1

问题 :如何消除错误以及如何正确设置我的 gitlab CI/CD?

详细信息:我(部分(遵循了本指南,并制作了一个这样的.gitlab-ci.yml文件:

image: continuumio/miniconda3:latest
testbuild :
stage: build
script:
- conda create --name test_env --file requirements.txt
- source activate test_env
- python setup.py install
tests:
stage: test
script:
- cd tests && pytest .

我的项目架构:

$ tree -L 1
project
├── package1/
├── package2/
├── data/
├── out/
├── __pycache__
├── requirements.txt
├── setup.py
└── tests/

我的requirements.txt(为了方便读者,从很多无用的东西中剥离出来(,它是用命令创建的conda list -e

# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
scikit-learn=0.20.0=py36h4989274_1
scipy=1.1.0=py36hfa4b5c9_1
# ...
setuptools=40.4.3=py36_0
pip=10.0.1=py36_0
py=1.7.0=py36_0
pytest=3.9.1=py36_0
python=3.6.6=h6e4f718_2
wheel=0.32.1=py36_0

我已将.gitlab-ci.yml更改为:

image: continuumio/miniconda3:latest
testbuild :
stage: build
script:
- conda create --name test_env --file requirements.txt
- source activate test_env
- python setup.py install
- cd tests && pytest .

在同一部分中重新组合teststestbuild。它现在可以工作了,它安装了所有内容并运行测试,尽管感觉这是一种糟糕的方法,因为我不再进行分离了。

正如Hoefling在评论中所说,问题在于gitlab在阶段之间没有保护环境。如果你真的想把这两者分开,看看这个: GitLab CI 在构建阶段之间保留环境

最新更新