moto not compatible with mock 4.0.3

Created on 10 Dec 2020  路  13Comments  路  Source: spulec/moto

Versions
Using moto-1.3.16 (boto-2.49.0 boto3-1.16.20 botocore-1.19.33)

Problem
Mock has released 5h ago a new version: 4.0.3
Since then our tests are failing with the exception below.

Fix
Forcing the version of mock to 4.0.2 is solving our issue

Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/__main__.py", line 18, in <module>
    main(module=None)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/main.py", line 101, in __init__
    self.runTests()
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/main.py", line 271, in runTests
    self.result = testRunner.run(self.test)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/runner.py", line 176, in run
    test(result)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/suite.py", line 122, in run
    test(result)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/suite.py", line 122, in run
    test(result)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/suite.py", line 122, in run
    test(result)
  File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/case.py", line 653, in __call__
    return self.run(*args, **kwds)
  File "../.venv/lib/python3.9/site-packages/moto/core/models.py", line 102, in wrapper
    self.stop()
  File "../.venv/lib/python3.9/site-packages/moto/core/models.py", line 86, in stop
    self.default_session_mock.stop()
  File "../.venv/lib/python3.9/site-packages/mock/mock.py", line 1563, in stop
    return self.__exit__(None, None, None)
  File "../.venv/lib/python3.9/site-packages/mock/mock.py", line 1529, in __exit__
    if self.is_local and self.temp_original is not DEFAULT:
bug

Most helpful comment

I have this problem as well. Using boto3==1.16.28 my current workaround is either
moto==1.3.14 mock==4.0.3
or
moto==1.3.16 mock==4.0.2

All 13 comments

Thanks for raising it @etiennechabert - will investigate

Do you have an example test case? I can't reproduce this with a bare-bones scenario:

pip install moto
pip show mock
Version: 4.0.3
@mock_s3
def test_x():
  print("working")

Can you please add to yours:

  • @mock_cloudwatch
  • @mock_sts

With @mock_s3 these are all the mock we are using in the test failing with mock 4.0.3.

Additionally, we are also using @set_initial_no_auth_action_count(1) (moto.core) inside of a @mock_sts

Let me know if this helps, otherwise I come back with more tomorrow.

Still no luck with this test case, @etiennechabert:

import boto3
from moto import mock_cloudwatch, mock_s3, mock_sts
from moto.core import set_initial_no_auth_action_count


@mock_cloudwatch
@mock_s3
@mock_sts
def test_x():
    s3 = boto3.client("s3", region_name="us-east-1")

    @set_initial_no_auth_action_count(1)
    def inside():
        print("inside")
    print(s3)
    inside()

I'm testing this all on Linux (Ubuntu 20.04.1), although I'm assuming that doesn't make a difference..

can you try this?

import unittest

import boto3
from moto import mock_s3


@mock_s3
class MyTestCase(unittest.TestCase):

    def test_x(self):
        s3 = boto3.client("s3", region_name="us-east-1")

        def inside():
            print("inside")

        print(s3)
        inside()


if __name__ == "__main__":
    unittest.main()

Thanks @ostashkevych - didn't think about the possibility of a class-decorator. i can reproduce it with that.

Attached a PR that should fix this issue.

Thanks a lot for your help @ostashkevych

To add search visibility, in my case the tests were failing with

AttributeError: '_patch' object has no attribute 'is_local'

While we wait on the PR, I just threw in the mock==4.0.2 requirement.

I'm having the same issue, my versions are:

boto3==1.16.35
moto==1.3.16
pynamodb==4.3.3
mock==4.0.2

was automatically installed (found out via $ pip freeze|grep mock )

@kzkv did mock==4.0.2 fix the issue for you? It didn't for me.

I'm trying to find which version of moto/mock doesn't show the bug.

Yes, it did! But in my case I had mock==4.0.3 in pip list before the change.

Thanks!

I have now mock==4.0.3 (which wasn't in my requirements.txt before) and I'm testing different moto versions.

moto==1.3.16 ==> FAIL (as expected)
moto==1.3.15 ==> FAIL
moto==1.3.14 ==> PASS

So in summary this version combination worked for me:

boto3==1.16.35
moto==1.3.14
mock==4.0.3

I have this problem as well. Using boto3==1.16.28 my current workaround is either
moto==1.3.14 mock==4.0.3
or
moto==1.3.16 mock==4.0.2

The version 0.12.1 of responses in use with moto 1.3.16 (whether mock 4.0.2/3) also had a separate issue when using to test fetching presigned urls that I resolved by reverting to 0.12.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mdavis-xyz picture mdavis-xyz  路  4Comments

JackDanger picture JackDanger  路  5Comments

dazza-codes picture dazza-codes  路  3Comments

joelhess picture joelhess  路  5Comments

kevgliss picture kevgliss  路  4Comments