python-3.x - 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 .
tests
在同testbuild
一部分重新组合。它现在可以工作了,它会安装所有东西并运行测试,尽管感觉这样做是一种糟糕的方式,因为我不再进行分离了。
正如hoefling在评论中所说,问题在于gitlab没有保留阶段之间的环境。如果您确实想将这两者分开,请查看:GitLab CI 在构建阶段之间保留环境
推荐阅读
- machine-learning - 在 CNN 中,内核/过滤器的数量是否与每一层的神经元相同?
- django - TemplateDoesNotExist at / Django 中的错误
- php - AJAX 请求未从服务器正确返回项目
- r - 在 R 中检查缺失数据模式的最优雅方法是什么?
- java - Java Streams如何在映射新列表时检查空值并发送消息
- html - Vue将输入值传递给TD,并在循环内使用v-model
- dataframe - 如何添加条件,以便当数据框具有某些列时,仅添加相应的“何时”条件
- python - Itertools.product 构建中介导致内存?
- css - 2 行中的 12 个 Angular Material Mat 选项卡如何实现?
- c++ - 赋值运算符在循环双向链表中无法正常工作