我遇到了 Travis CI 构建错误 "Module not found" 我不确定为什么
I'm getting the Travis CI Build Error "Module not found" and I'm not sure why
我的 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"]
我的 travis.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.
我的 requirements.txt 文件包含以下内容:
pytest==4.6
requests
模块是您的 requirements.txt 文件的一部分吗?如果没有,那就是问题所在。 requests
有时会默认安装,但通常不会像 Travis 通常运行的那样在 Linux 发行版中安装。
requirements.txt 可以看起来像:
pytest==4.6
requests~=2.6.0
我的 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"]
我的 travis.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.
我的 requirements.txt 文件包含以下内容:
pytest==4.6
requests
模块是您的 requirements.txt 文件的一部分吗?如果没有,那就是问题所在。 requests
有时会默认安装,但通常不会像 Travis 通常运行的那样在 Linux 发行版中安装。
requirements.txt 可以看起来像:
pytest==4.6
requests~=2.6.0