Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation warnings using mock_dynamodb2 with python 3.8.2 #2978

Closed
mowat27 opened this issue May 8, 2020 · 5 comments · Fixed by #3503
Closed

Deprecation warnings using mock_dynamodb2 with python 3.8.2 #2978

mowat27 opened this issue May 8, 2020 · 5 comments · Fixed by #3503

Comments

@mowat27
Copy link

mowat27 commented May 8, 2020

Behaviour

When I use mock_dynamodb2 with python 3.8.2 I get deprecation warnings.

Versions

$ pipenv run pip freeze | grep -E 'moto|boto'
boto==2.49.0
boto3==1.13.5
botocore==1.16.5
moto==1.3.14
$ pipenv run python -V
Python 3.8.2

Moto was installed using Pipenv

Example

Given the following pytest file...

import os
import pytest
import boto3
from moto import mock_dynamodb2


os.environ['AWS_ACCESS_KEY_ID'] = 'testing'
os.environ['AWS_SECRET_ACCESS_KEY'] = 'testing'
os.environ['AWS_SECURITY_TOKEN'] = 'testing'
os.environ['AWS_SESSION_TOKEN'] = 'testing'


@pytest.fixture
def ddb(scope='function'):
    with mock_dynamodb2():
        return boto3.client('dynamodb',
                            region_name='eu-west-1',
                            aws_access_key_id='testing',
                            aws_secret_access_key='testing',
                            aws_session_token='testing')


@mock_dynamodb2
def test_listing_tables(ddb):
    # table_name = 'temp-{}'.format(str(uuid4()))
    ddb.create_table(
        AttributeDefinitions=[
            {
                'AttributeName': 'Artist',
                'AttributeType': 'S',
            },
            {
                'AttributeName': 'SongTitle',
                'AttributeType': 'S',
            }
        ],
        KeySchema=[
            {
                'AttributeName': 'Artist',
                'KeyType': 'HASH',
            },
            {
                'AttributeName': 'SongTitle',
                'KeyType': 'RANGE',
            }
        ],
        ProvisionedThroughput={
            'ReadCapacityUnits': 5,
            'WriteCapacityUnits': 5,
        },
        TableName='Music',
    )
    assert ddb.list_tables()['TableNames'] == ['Music']

Deprecation warnings when I run pytest

$ pipenv run pytest
======================================================================================= test session starts =======================================================================================
platform darwin -- Python 3.8.2, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: /Users/adrian/code/mowat27/learn/aws/ddbmock, inifile: pytest.ini
collected 1 item

test/test_put_and_scan.py .                                                                                                                                                                 [100%]

======================================================================================== warnings summary =========================================================================================
/Users/adrian/.local/share/virtualenvs/ddbmock-o4qurhhV/lib/python3.8/site-packages/boto/plugin.py:40
  /Users/adrian/.local/share/virtualenvs/ddbmock-o4qurhhV/lib/python3.8/site-packages/boto/plugin.py:40: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

/Users/adrian/.local/share/virtualenvs/ddbmock-o4qurhhV/lib/python3.8/site-packages/moto/cloudformation/parsing.py:407
  /Users/adrian/.local/share/virtualenvs/ddbmock-o4qurhhV/lib/python3.8/site-packages/moto/cloudformation/parsing.py:407: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
    class ResourceMap(collections.Mapping):

-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================================================== 1 passed, 2 warnings in 2.86s ==================================================================================

Expected behaviour

No warnings

This is annoying but not critical at the moment. I'd like to keep my project up to date with future python releases though.

Related issues

A search for DeprecationWarning in open issues yielded no results. Sorry if I missed something.

@mowat27
Copy link
Author

mowat27 commented May 8, 2020

If anyone else is having this problem, note that you can work around this by changing the imports in your test suite to supress the warnings

import warnings

with warnings.catch_warnings():
     warnings.filterwarnings("ignore", category=DeprecationWarning)
     import boto3
     from moto import mock_dynamodb2

or by using pytest.ini

[pytest]
filterwarnings =
    ignore::DeprecationWarning:moto.*:
    ignore::DeprecationWarning:boto.*:

@bblommers
Copy link
Collaborator

Thanks for raising this, and for providing a workaround, @mowat27. Marking this as an enhancement.

@gruebel
Copy link
Contributor

gruebel commented May 12, 2020

Hi @bblommers, it looks like the issue was already fixed on the master #2624
Maybe it is time for a new release again?

@bblommers
Copy link
Collaborator

This should now be fixed as of moto >= 1.3.16.

@qbiqing
Copy link

qbiqing commented Sep 29, 2020

I am using moto v1.3.16, installed with pipenv, and this warning still appears. In my case I'm using mock_s3.

  /usr/local/lib/python3.8/site-packages/boto/plugin.py:40: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

-- Docs: https://docs.pytest.org/en/stable/warnings.html

bpandola added a commit to bpandola/moto that referenced this issue Nov 27, 2020
The `boto` library (long ago superseded by `boto3`) has not had an official
release in over two years or even a commit in the last 18 months.  Importing
the package (or indirectly importing it by via `moto`) generates a deprecation
warning.  Additionally, an ever-increasing number of `moto` users who have
left `boto` behind for `boto3` are still being forced to install `boto`.

This commit vendors a very small subset of the `boto` library--only the code
required by `moto` to run--into the /packages subdirectory.  A README file
is included explaining the origin of the files and a recommendation for how
they can be removed entirely in a future release.

NOTE: Users of `boto` will still be able to use `moto` after this is merged.

closes getmoto#2978
closes getmoto#3013
closes getmoto#3170
closes getmoto#3418

relates to getmoto#2950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants