moto: moto not compatible with mock 4.0.3

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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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/python@3.9/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:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 38
  • Comments: 24

Commits related to this issue

Most upvoted comments

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

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

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.

We’ve just released a fix, and Moto >= 1.3.17.dev264 should be compatible with mock == 4.0.3.

Please let us know if you’re still experiencing issues.

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()

That boundary should be fine afaik, @potiuk. Moto only requires boto3>=1.9.201, because they do a good job of keeping things backward compatible. There’s no relation between versions, though. There are best efforts to keep it working with the latest version of boto3, and to only require a boto3-update if absolutely necessary.

For reference. I was receiving the following TypeError:

  File "/usr/local/lib/python3.6/dist-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/responses.py", line 733, in unbound_on_send
    return self._on_request(adapter, request, *a, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/responses.py", line 680, in _on_request
    match, match_failed_reasons = self._find_match(request)
TypeError: 'CallbackResponse' object is not iterable

When executing the following code:

    @mock_sqs
    def test_36(self):
        print(requests.get('http://localhost:3000/businesses/6c213885-7b2c-425a-8280-9af507d9ff07/sites'))

It was fixed as suggested by @marcelloromani by setting

boto3==1.16.28 # AWS library
moto==1.3.14  # Mock boto3 client in unittests
mock==4.0.3

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.