我得到" Module not found ";我的Travis CI构建错误。我不确定确切的原因,但这里看看我的初始PyTest文件:
import requests
url_ddg = "https://api.duckduckgo.com"
def test_ddg0():
resp = requests.get(url_ddg + "/?q=DuckDuckGo&format=json")
rsp_data = resp.json()
assert "DuckDuckGo" in rsp_data["Heading"]
我的特拉维斯。Yml文件包含以下代码:
language: python
python:
- "3.8.2"
- "nightly"
install:
- "pip install pytest"
- "pip install -r requirements.txt"
script: python -m pytest Test.py
下面是Travis构建日志中的错误:
==================================== ERRORS ====================================
___________________________ ERROR collecting Test.py ___________________________
ImportError while importing test module '/home/travis/build/mjfields-java/PresidentsAPI/Test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
Test.py:1: in <module>
import requests
E ModuleNotFoundError: No module named 'requests'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.07 seconds ============================
The command "python -m pytest Test.py" exited with 2.
Done. Your build exited with 1.
My requirements.txt文件包含如下内容:
pytest==4.6
requests
模块是您的requirements.txt文件的一部分吗?如果不是,那就是问题所在。requests
有时是默认安装的,但通常不在像Travis那样的Linux发行版中。
requirements.txt看起来像:
pytest==4.6
requests~=2.6.0