question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

moto not compatible with mock 4.0.3

See original GitHub issue

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:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:38
  • Comments:24

github_iconTop GitHub Comments

8reactions
hadancommented, Dec 15, 2020

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

6reactions
marcelloromanicommented, Dec 14, 2020

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
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started with Moto — Moto 4.0.13.dev documentation
You can use pip to install the latest released version of moto , and specify which service(s) you will ... You can also...
Read more >
Moto does not work with python unit test setUp() call
It appears that moto is working properly if all of the mocking code is contained in the test method.
Read more >
moto - PyPI
Moto is a library that allows your tests to easily mock out AWS Services. Imagine you have the following python code that you...
Read more >
Moto Documentation - Read the Docs
a package-level S3 client will properly use the mock and not reach␣ ... This is to make tests compatible with the moto server....
Read more >
mock: Docs, Community, Tutorials, Reviews | Openbase
This package contains a rolling backport of the standard library mock code compatible with Python 3.6 and up. Please see the standard library...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found