【发布时间】:2019-11-25 06:13:11
【问题描述】:
我正在尝试 pylint 我的测试套件,该套件使用 moto 模块进行 AWS API 模型。
这是我超级简单的测试用例:
import moto
不幸的是它失败了pylint:
~/prj $ pylint test_moto.py
************* Module test_test
test_moto.py:1:0: E0401: Unable to import 'moto' (import-error)
test_moto.py:1:0: W0611: Unused import moto (unused-import)
----------------------------------------------------------------------
Your code has been rated at -50.00/10 (previous run: -50.00/10, +0.00)
但是我的 virtualenv 中确实安装了 moto 并且它可以工作:
~/prj $ python
Python 3.6.8 (default, Oct 7 2019, 12:59:55)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import moto
>>> moto.__version__
'1.3.14'
>>>
这是我的pylint:
~/prj $ pylint --version
pylint 2.3.1
astroid 2.2.5
Python 3.6.8 (default, Oct 7 2019, 12:59:55)
[GCC 8.3.0]
python 和 pylint 都在 virtualenv 中:
~/prj $ which python
/home/me/.virtualenvs/prjenv/bin/python
~/prj $ which pylint
/home/me/.virtualenvs/prjenv/bin/pylint
为什么 pylint 抱怨进口?我怎样才能阻止它?
【问题讨论】:
-
运行你用来运行代码的python安装的pylint。如果两者都在不同的地方(例如,一个在 venv 中,另一个在全局系统组件中),那么事情可能会出错。
-
@Jens 感谢您的建议,他们都在虚拟环境中。我已经更新了问题。
-
您是否有文件
moto.py可能会影响模块? -
@Jens 不,只有
test_moto.py和main.py。