0

I'm trying to pylint my testsuite that uses moto module for AWS API mockup.

This is my super simple testcase:

import moto

Unfortunately it fails 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)

However I do have moto installed in my virtualenv and it works:

~/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'
>>> 

This is my 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]

Both python and pylint are in the virtualenv:

~/prj $ which python
/home/me/.virtualenvs/prjenv/bin/python
~/prj $ which pylint
/home/me/.virtualenvs/prjenv/bin/pylint

Why is pylint complaining about the import? How can I stop it?

MLu
  • 1,218
  • 2
  • 15
  • 28
  • Run the pylint that is installed by the python you use to run your code. If both are in different places (e.g. one in a venv and the other a global system component) then things can go awry. – Jens Nov 18 '19 at 04:16
  • @Jens thanks for the suggestion, they are both in the virtual env. I have updated the question. – MLu Nov 18 '19 at 04:22
  • Do you have a file `moto.py` that might shadow the module? – Jens Nov 18 '19 at 06:26
  • @Jens nope, only `test_moto.py` and `main.py`. – MLu Nov 18 '19 at 07:56

1 Answers1

0

It turns out it's an issue with pylint 2.3.x that doesn't work well with boto3 and in turn with moto. See https://github.com/PyCQA/pylint/issues/3261

Downgrading to pylint 2.2.x solves this problem.

MLu
  • 1,218
  • 2
  • 15
  • 28