python-3.x - Gitlab CI/CD : Pytest running with Conda

标签 python-3.x continuous-integration gitlab pytest conda

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

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

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

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

详细信息:我(部分)关注了 this guide ,我已经做了一个 .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 preserve environment between build stages

关于python-3.x - Gitlab CI/CD : Pytest running with Conda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52994662/

相关文章:

Python-如何将函数参数转换为数值运算符/float()/int()?

python - 如何将导入的txt文件的文件名添加到python中的数据帧

.net - CruiseControl.NET 中的构建顺序与项目依赖项

git - 如何解决 GitLab 上的冲突?

通过 nginx 代理的 Docker 环境导致 502 Bad Gateway

python - 使用嵌套字典列表过滤数据框

python - 使用 Python 3.4 创建的 ReportLab pdf 中缺少字母 č

ruby - Jekyll 无法在 Manjaro Linux 上部署 - Sass-Listen-4.0.0 无法在部署时安装(GitLab、Netlify)

encryption - 在公共(public)存储库中使用 Travis-CI 构建通知 Hook 保持 API key 完整性

maven-2 - 使用 maven2 进行 eclipse rcp 项目的构建自动化和持续集成?