我正在尝试设置自动测试 我的Python包 使用Travis CI。我的Python包依赖于 鸢尾花 以及其他包,如PyYAML、numpy等。它还依赖于PyPI包 (脚本引擎). 现在,我想使用conda(安装Iris)和pip(安装PyPI包以及检查PyYAML和numpy的需求)建立一个Travis CI环境。然后我想使用 pip install .
.
为了测试这是否可行,我写了一个简单的Pytest测试,导入PyYAML。
我目前正在尝试使用这个 .travis.yml
文件。
language: python
python:
- "3.6"
- "3.7"
- "3.8"
# command to install dependencies
install:
- sudo apt-get update
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- source "$HOME/miniconda/etc/profile.d/conda.sh"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
- conda env create -f tests/test-environment.yml python=$TRAVIS_PYTHON_VERSION
- conda activate test-environment
- conda install pip
- conda install -c conda-forge iris
- pip install -r requirements.txt
- pip install .
# command to run tests
script: pytest
注:这是我第一次真正使用Travis CI。这个脚本混合了来自 Conda docs 以及Travis CI文档。
然后Pytest导入PyYAML失败了(尽管它因为requirements.txt以及Iris依赖关系而被安装了):这是日志中确认它被安装了。
Requirement already satisfied: pyYAML>=5.1 in /home/travis/miniconda/envs/test-environment/lib/python3.8/site-packages (from ece-4-monitoring==0.1.0) (5.3.1)
这是Pytest的Error:
$ pytest
============================= test session starts ==============================
platform linux -- Python 3.7.1, pytest-4.3.1, py-1.7.0, pluggy-0.8.0
rootdir: /home/travis/build/valentinaschueller/ece-4-monitoring, inifile:
collected 1 item / 1 errors
==================================== ERRORS ====================================
_________________ ERROR collecting tests/test_file_handling.py _________________
ImportError while importing test module '/home/travis/build/valentinaschueller/sciptengine-tasks-ecearth/tests/test_file_handling.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_file_handling.py:3: in <module>
import helpers.file_handling as file_handling
helpers/file_handling.py:1: in <module>
import yaml
E ModuleNotFoundError: No module named 'yaml'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.12 seconds ============================
The command "pytest" exited with 2.
如果我在我的电脑上使用本地的conda虚拟环境来尝试这个设置,我就不会出现这个问题。为什么在Travis CI虚拟机上不能工作?