python - Pytest 在具有 PyPI 和 conda 包依赖项的 Travis CI 测试中找不到 pyYAML
问题描述
我正在尝试使用 Travis CI为我的 Python 包设置自动测试。我的 Python 包依赖于Iris以及其他包,例如 PyYAML、numpy 等。它还依赖于 PyPI 包 ( ScriptEngine )。现在,我想使用 conda(安装 Iris)和 pip(安装 PyPI 包以及检查 PyYAML 和 numpy 的要求)设置 Travis CI 环境。然后我想使用pip install .
.
为了测试这是否可行,我编写了一个导入 PyYAML 的简单 Pytest 测试。
我目前正在尝试使用此.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 文档和 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 的错误:
$ 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 虚拟机上不起作用?
解决方案
推荐阅读
- java - 如何使用 JUnit 测试读写锁?
- video-processing - 我正在使用 scc cfg 文件运行 HECV-SCM 编码器,但它无法输出 IDR 帧
- python - Flask:获取 AttributeError:'_AppCtxGlobals' 对象没有属性
- html - 尽管 CSS 中存在“pointer-event:none”,但绝对定位的叠加层会通过悬停事件
- swift - Firebase 查询语句 whereField(notIn) 不起作用
- html - flexbox中的水平滚动溢出父级
- android-studio - 如何在连续模式下配置 ktlint gradle 插件?
- typescript - 加载前更改模块内的 VUE 组件
- lisp - 从文件中剪辑阅读列表并将其展平,但不工作,不将 lst 识别为列表
- php - Symfony/Doctrine:获取可用命令列表