Message7666
tl;dr
try:
import mock
except ImportError:
import unittest.mock as mock
I have no error of that type in CI (ubuntu 3.11 and lower). What is your
OS?
On my dev system (ubuntu 20.04):
>>> import sys
>>> import mock
>>> sys.modules['mock']
<module 'mock' from '/usr/lib/python3/dist-packages/mock/__init__.py'>
>>> sys.version
'3.6.9 (default, Jun 29 2022, 11:45:57) \n[GCC 8.4.0]'
but on my rasp pi:
>>> import sys
>>> import mock
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mock'
>>> sys.version
'3.9.2 (default, Mar 12 2021, 04:06:34) \n[GCC 10.2.1 20210110]'
searching for python mock I get:
https://docs.python.org/3/library/unittest.mock.html
>>> import unittest.mock
>>> sys.modules['unittest.mock']
<module 'unittest.mock' from '/usr/lib/python3.9/unittest/mock.py'>
and the code reads:
def test_native_autoselect(self):
import mock, sys
with mock.patch.dict('sys.modules',
and the unitest.mock.patch() is a context manager. So I am going with that.
but google isn't showing any indication that it moved.
pip3 shows mock 2.0.0 and
https://pypi.org/project/mock/ references unittest.mock as of python 3.3.
My guess is mock/mock.py was installed as a (default) package in some python
distributions:
% dpkg -S /usr/lib/python3/dist-packages/mock/mock.py
python3-mock: /usr/lib/python3/dist-packages/mock/mock.py |
|
Date |
User |
Action |
Args |
2022-11-23 15:25:05 | rouilj | set | messageid: <1669217105.21.0.0744737154901.issue2551242@roundup.psfhosted.org> |
2022-11-23 15:25:05 | rouilj | set | recipients:
+ rouilj, schlatterbeck |
2022-11-23 15:25:05 | rouilj | link | issue2551242 messages |
2022-11-23 15:25:04 | rouilj | create | |
|