Python Pytest在具有PyPI和conda包依赖项的Travis CI测试中找不到pyYAML

Python Pytest在具有PyPI和conda包依赖项的Travis CI测试中找不到pyYAML,python,pip,conda,travis-ci,pyyaml,Python,Pip,Conda,Travis Ci,Pyyaml,我正在尝试设置使用Travis CI的自动测试。我的Python包依赖于PyYAML、numpy等其他包。它还依赖于PyPI包()。现在,我想使用conda(安装Iris)和pip(安装PyPI包并检查PyYAML和numpy的需求)来设置一个travisci环境。然后,我想使用pip安装安装我的软件包。 为了测试这是否有效,我编写了一个简单的Pytest测试来导入PyYAML 我目前正试图使用此.travis.yml文件执行此操作: 语言:python 蟒蛇: - "3.6" - "3.7"

我正在尝试设置使用Travis CI的自动测试。我的Python包依赖于PyYAML、numpy等其他包。它还依赖于PyPI包()。现在,我想使用conda(安装Iris)和pip(安装PyPI包并检查PyYAML和numpy的需求)来设置一个travisci环境。然后,我想使用
pip安装安装我的软件包。

为了测试这是否有效,我编写了一个简单的Pytest测试来导入PyYAML

我目前正试图使用此
.travis.yml
文件执行此操作:

语言:python
蟒蛇:
- "3.6"
- "3.7"
- "3.8"
#用于安装依赖项的命令
安装:
-sudoapt获得更新
-wgethttps://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
-bash miniconda.sh-b-p$HOME/miniconda
-来源“$HOME/miniconda/etc/profile.d/conda.sh”
-hash-r
-conda配置--设置始终\u是是--设置更改1否
-康达更新-q康达
#用于调试conda的任何问题
-康达信息-a
-conda env create-f tests/test-environment.yml python=$TRAVIS\u python\u VERSION
-康达激活测试环境
-康达安装pip
-conda安装-c conda forge iris
-pip安装-r requirements.txt
-pip安装。
#运行测试的命令
脚本:pytest
注意:这是我第一次真正与Travis CI合作。此脚本混合了来自的示例以及Travis CI文档

Pytest随后无法导入PyYAML(尽管由于requirements.txt和Iris依赖关系而安装了PyYAML): 以下是日志中的安装确认信息:

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.
$pytest
===========================================测试会话开始==============================
平台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,文件:
收集了1项/1个错误
===================================================错误====================================
_________________收集测试/测试文件\u handling.py时出错_________________
导入测试模块“/home/travis/build/valentinaschueller/sciptengine tasks ecearth/tests/test_file_handling.py”时导入错误。
提示:确保您的测试模块/包具有有效的Python名称。
回溯:
tests/test_file_handling.py:3:in
导入helpers.file\u处理作为文件处理
helpers/file_handling.py:1:in
进口yaml
E ModuleNotFoundError:没有名为“yaml”的模块
!!!!!!!!!!!!!!!!!!! 中断:收集过程中出现1个错误!!!!!!!!!!!!!!!!!!!!
===========================================0.12秒内出现1个错误============================
命令“pytest”以2退出。
如果我在本地计算机上使用conda虚拟环境尝试此精确设置,我不会遇到此问题。为什么这在Travis CI虚拟机上不起作用?

如中所述:我可以通过在
requirements.txt
中明确要求pytest来解决此问题


无需在脚本部分中激活测试环境。然而,一个非常有用的提示是使用
echo$(哪个pytest)和&pytest
而不是只使用
pytest
来检查pytest是否安装在
/home/travis/miniconda/envs/test-environment/bin/pytest
中,对吗?出于调试目的,我将
-script:pytest
更改为
script:echo$(哪个pytest)和&pytest
,并确保打印的路径是
/home/travis/miniconda/envs/test environment/bin/pytest
-我不确定是否也必须在
-script
部分中激活
测试环境,非常感谢你!问题确实是在
requirements.txt
中没有明确提到pytest。