Repository: getmoto/moto

Issue:
Tests failing on master
I want to write a patch for moto. To start with, I'm trying to run unit tests on master prior to me writing any code.

Those tests are failing.

I'm following [these instructions](http://docs.getmoto.org/en/latest/docs/contributing/installation.html#contributing-installation).

I've checked out commit 6da12892a3c18248a2cfe55bc7d2cb3039817684, which is the latest master commit.


When I run `make test`, it fails.

```
$ make test
Running flake8...
flake8 moto tests
Running black... 
(Make sure you have black-22.3.0 installed, as other versions will produce different results)
black --check moto/ tests/
All done! ✨ 🍰 ✨
1485 files would be left unchanged.
Running pylint...
pylint -j 0 moto tests

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

Running MyPy...
mypy --install-types --non-interactive
Installing missing stub packages:
/Users/matthew/.pyenv/versions/3.10.0/bin/python3.10 -m pip install types-PyYAML types-python-dateutil types-requests

Collecting types-PyYAML
  Using cached types_PyYAML-6.0.12.2-py3-none-any.whl (14 kB)
Collecting types-python-dateutil
  Using cached types_python_dateutil-2.8.19.5-py3-none-any.whl (9.1 kB)
Collecting types-requests
  Using cached types_requests-2.28.11.7-py3-none-any.whl (14 kB)
Collecting types-urllib3<1.27
  Using cached types_urllib3-1.26.25.4-py3-none-any.whl (14 kB)
Installing collected packages: types-urllib3, types-requests, types-PyYAML, types-python-dateutil
Successfully installed types-PyYAML-6.0.12.2 types-python-dateutil-2.8.19.5 types-requests-2.28.11.7 types-urllib3-1.26.25.4
WARNING: You are using pip version 21.2.3; however, version 22.3.1 is available.
You should consider upgrading via the '/Users/matthew/.pyenv/versions/3.10.0/bin/python3.10 -m pip install --upgrade pip' command.

/Users/matthew/.pyenv/versions/3.10.0/lib/python3.10/site-packages/mypy/typeshed/stdlib/unittest/mock.pyi: error: Source file found twice under different module names: "unittest.mock" and "mypy.typeshed.stdlib.unittest.mock"
Found 1 error in 1 file (errors prevented further checking)
make: *** [lint] Error 2
```

I'm running on a macbook, python 3.10.0.

`pip3 list` gives:

```
$ pip3 list
Package                          Version     Location
-------------------------------- ----------- -----------------------------------------------------
aenum                            3.1.11
aiobotocore                      2.2.0
aiohttp                          3.8.1
aioitertools                     0.10.0
aiosignal                        1.2.0
ansible                          6.4.0
ansible-core                     2.13.5
anyio                            3.5.0
appnope                          0.1.3
argon2-cffi                      21.3.0
argon2-cffi-bindings             21.2.0
asn1crypto                       1.5.1
astroid                          2.13.2
asttokens                        2.0.5
async-timeout                    4.0.2
attrs                            21.4.0
aws-cdk-lib                      2.45.0
aws-sam-translator               1.56.0
aws-wsgi                         0.2.7
aws-xray-sdk                     2.11.0
awswrangler                      2.15.1
Babel                            2.10.1
backcall                         0.2.0
backoff                          2.1.2
bcrypt                           3.2.2
beautifulsoup4                   4.11.1
black                            22.3.0
bleach                           5.0.0
boto                             2.49.0
boto3                            1.21.34
botocore                         1.24.46
build                            0.10.0
cattrs                           22.1.0
certifi                          2021.10.8
cffi                             1.15.0
cfn-lint                         0.72.8
charset-normalizer               2.0.12
click                            8.1.3
click-default-group-wheel        1.2.2
colorama                         0.4.4
constructs                       10.1.129
coverage                         7.0.5
cramjam                          2.5.0
cryptography                     37.0.2
curlify                          2.2.1
cursor                           1.3.4
debugpy                          1.6.0
decorator                        5.1.1
defusedxml                       0.7.1
diagrams                         0.21.1
dill                             0.3.6
distlib                          0.3.6
docker                           6.0.0
ecdsa                            0.18.0
entrypoints                      0.4
et-xmlfile                       1.1.0
exceptiongroup                   1.0.0rc9
execnet                          1.9.0
executing                        0.8.3
fabric                           2.7.1
fastjsonschema                   2.15.3
fastparquet                      0.8.1
filelock                         3.8.0
flake8                           4.0.1
flake8-print                     5.0.0
flake8-use-fstring               1.4
Flask                            2.0.3
Flask-BasicAuth                  0.2.0
Flask-Cors                       3.0.10
flask-talisman                   1.0.0
freezegun                        1.2.2
frozenlist                       1.3.0
fsspec                           2022.3.0
gevent                           22.8.0
graphql-core                     3.2.1
graphviz                         0.19.2
greenlet                         1.1.3.post0
gremlinpython                    3.6.0
halo                             0.0.29
hypothesis                       6.54.5
hypothesis-graphql               0.9.1
hypothesis-jsonschema            0.22.0
idna                             3.3
importlib-resources              5.10.2
inflection                       0.5.1
iniconfig                        1.1.1
invoke                           1.7.3
ipykernel                        6.13.0
ipython                          8.3.0
ipython-genutils                 0.2.0
isodate                          0.6.1
isort                            5.11.4
itsdangerous                     2.1.2
jedi                             0.18.1
Jinja2                           3.1.2
jmespath                         1.0.0
jschema-to-python                1.2.3
jsii                             1.69.0
json5                            0.9.8
jsondiff                         2.0.0
jsonpatch                        1.32
jsonpath-ng                      1.5.3
jsonpickle                       3.0.1
jsonpointer                      2.3
jsonschema                       4.5.1
jsonschema-spec                  0.1.2
junit-xml                        1.9
jupyter-client                   7.3.1
jupyter-core                     4.10.0
jupyter-server                   1.17.0
jupyterlab                       3.4.0
jupyterlab-pygments              0.2.2
jupyterlab-server                2.13.0
lazy-object-proxy                1.9.0
log-symbols                      0.0.14
lxml                             4.8.0
MarkupSafe                       2.1.1
matplotlib-inline                0.1.3
mccabe                           0.6.1
mistune                          0.8.4
mms                              5.1         /Users/matthew/Documents/repo/workload/docker/mms
moto                             4.1.0.dev0  /Users/matthew/Documents/moto
multidict                        6.0.2
mypy                             0.991
mypy-extensions                  0.4.3
nbclassic                        0.3.7
nbclient                         0.6.3
nbconvert                        6.5.0
nbformat                         5.4.0
nemreader                        0.7.0
nest-asyncio                     1.5.5
networkx                         2.8.8
notebook                         6.4.11
notebook-shim                    0.1.0
numpy                            1.22.4
openapi-schema-validator         0.3.4
openapi-spec-validator           0.5.1
openpyxl                         3.0.10
opensearch-py                    1.1.0
packaging                        21.3
pandas                           1.4.2
pandocfilters                    1.5.0
paramiko                         2.11.0
parquet-tools                    0.2.10
parso                            0.8.3
pathable                         0.4.3
pathlib2                         2.3.7.post1
pathspec                         0.10.3
pbr                              5.11.1
pem                              21.2.0
pexpect                          4.8.0
pg8000                           1.29.1
pickleshare                      0.7.5
pip                              21.2.3
platformdirs                     2.5.2
pluggy                           1.0.0
ply                              3.11
prettytable                      3.5.0
progressbar2                     4.0.0
prometheus-client                0.14.1
prompt-toolkit                   3.0.29
psutil                           5.9.0
ptyprocess                       0.7.0
publication                      0.0.3
pure-eval                        0.2.2
py                               1.11.0
py-bcrypt                        0.4
py-openapi-schema-to-json-schema 0.0.3
pyarrow                          7.0.0
pyasn1                           0.4.8
pycodestyle                      2.8.0
pycparser                        2.21
pydantic                         1.10.4
pyflakes                         2.4.0
Pygments                         2.12.0
pylint                           2.15.10
PyMySQL                          1.0.2
PyNaCl                           1.5.0
pyparsing                        3.0.8
PyPDF2                           2.10.7
pyproject_hooks                  1.0.0
pyrsistent                       0.18.1
pytest                           7.1.3
pytest-cov                       4.0.0
pytest-subtests                  0.7.0
pytest-xdist                     3.1.0
python-dateutil                  2.8.2
python-jose                      3.3.0
python-utils                     3.3.2
pytz                             2022.1
PyYAML                           6.0
pyzmq                            22.3.0
redshift-connector               2.0.907
requests                         2.27.1
requests-aws4auth                1.1.2
resolvelib                       0.8.1
responses                        0.21.0
retry                            0.9.2
rsa                              4.9
s3fs                             2022.3.0
s3transfer                       0.5.2
sarif-om                         1.0.4
schemathesis                     3.17.2
scramp                           1.4.1
Send2Trash                       1.8.0
setuptools                       57.4.0
simplejson                       3.18.0
six                              1.16.0
sniffio                          1.2.0
sortedcontainers                 2.4.0
soupsieve                        2.3.2.post1
spinners                         0.0.24
sqlite-fts4                      1.0.1
sqlite-utils                     3.26.1
sshpubkeys                       3.3.1
stack-data                       0.2.0
starlette                        0.20.4
surer                            0.0.3
tabulate                         0.8.9
tenergy                          0.3         /Users/matthew/Documents/repo/workload/common/tenergy
termcolor                        1.1.0
terminado                        0.13.3
thrift                           0.13.0
timeout-decorator                0.5.0
tinycss2                         1.1.1
tomli                            2.0.1
tomli_w                          1.0.0
tomlkit                          0.11.6
tornado                          6.1
tox                              3.26.0
traitlets                        5.1.1
typeguard                        2.13.3
typer                            0.4.1
types-python-dateutil            2.8.19.5
types-PyYAML                     6.0.12.2
types-requests                   2.28.11.7
types-urllib3                    1.26.25.4
typing_extensions                4.4.0
urllib3                          1.26.9
virtualenv                       20.16.5
wcwidth                          0.2.5
webencodings                     0.5.1
websocket                        0.2.1
websocket-client                 1.3.2
websockets                       10.3
Werkzeug                         2.1.2
wrapt                            1.14.1
xmltodict                        0.13.0
yarl                             1.7.2
zope.event                       4.5.0
zope.interface                   5.5.0
```


Discussion:
Looks similar to [this issue](https://github.com/getsentry/responses/issues/556). Can you upgrade `responses` to 0.22.0, and try again?
When I try with `responses==0.22.0` I get a different error:

```
Running MyPy...
mypy --install-types --non-interactive
Installing missing stub packages:
/Users/matthew/.pyenv/versions/3.10.0/bin/python3.10 -m pip install types-setuptools

Collecting types-setuptools
  Downloading types_setuptools-65.7.0.0-py3-none-any.whl (49 kB)
     |████████████████████████████████| 49 kB 2.9 MB/s 
Collecting types-docutils
  Downloading types_docutils-0.19.1.1-py3-none-any.whl (16 kB)
Installing collected packages: types-docutils, types-setuptools
Successfully installed types-docutils-0.19.1.1 types-setuptools-65.7.0.0
WARNING: You are using pip version 21.2.3; however, version 22.3.1 is available.
You should consider upgrading via the '/Users/matthew/.pyenv/versions/3.10.0/bin/python3.10 -m pip install --upgrade pip' command.

moto/core/custom_responses_mock.py:15:5: error: Name "version" already defined (possibly by an import)  [no-redef]
Found 1 error in 1 file (checked 209 source files)
make: *** [lint] Error 1
```
Interesting. I can see why mypy would complain there, but I do not understand why it doesn't complain in our CI, or in my local. 

Just to confirm - does mypy pass when adding `  # type: ignore[no-redef]` to that line? Or are there any other problems after that?
(Note the two spaces before the `#` - I believe black will complain if you don't have them...)
@bblommers I have also been running into the `mypy` error described above when trying to run tests locally. After adding the type ignore comment, the full test suite completed without errors.

Original error:
```
moto/core/custom_responses_mock.py:15:5: error: Name "version" already defined (possibly by an import)  [no-redef]
Found 1 error in 1 file (checked 209 source files)
make: *** [Makefile:31: lint] Error 1
```
Mypy test results after adding the comment:
```
Running MyPy...
mypy --install-types --non-interactive
Success: no issues found in 209 source files
rm -f .coverage
rm -rf cover
pytest -sv --cov=moto --cov-report xml ./tests/ --ignore tests/test_batch --ignore tests/test_ec2 --ignore tests/test_sqs
```

Resolving patch:
diff --git a/moto/core/custom_responses_mock.py b/moto/core/custom_responses_mock.py
--- a/moto/core/custom_responses_mock.py
+++ b/moto/core/custom_responses_mock.py
@@ -12,7 +12,7 @@
 try:
     from importlib.metadata import version
 except ImportError:
-    from importlib_metadata import version
+    from importlib_metadata import version  # type: ignore[no-redef]
 
 
 RESPONSES_VERSION = version("responses")


Test patch: