Issue 2551242
Created on 2022-11-23 06:34 by schlatterbeck, last changed 2022-11-24 15:08 by rouilj.
| Messages | |||
|---|---|---|---|
| msg7665 | Author: [hidden] (schlatterbeck) | Date: 2022-11-23 06:34 | |
Where is the 'mock' module supposed to come from?
Not found with Debian oldstable (Python3.7) and Debian stable (Python3.9)
=================================== FAILURES ===================================
____________________ Get_IndexerTest.test_native_autoselect ____________________
self = <test.test_indexer.Get_IndexerTest testMethod=test_native_autoselect>
def test_native_autoselect(self):
> import mock, sys
E ModuleNotFoundError: No module named 'mock'
test/test_indexer.py:290: ModuleNotFoundError
=========================== short test summary info ============================
FAILED test/test_indexer.py::Get_IndexerTest::test_native_autoselect - Module...
|
|||
| msg7666 | Author: [hidden] (rouilj) | Date: 2022-11-23 15:25 | |
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 |
|||
| msg7667 | Author: [hidden] (schlatterbeck) | Date: 2022-11-23 17:20 | |
On Wed, Nov 23, 2022 at 03:25:05PM +0000, John Rouillard wrote:
>
> try:
> import mock
> except ImportError:
> import unittest.mock as mock
OK, you know that roundup has its own mock module in
roundup/test/mocknull.py? Does this do the same thing?
>
> I have no error of that type in CI (ubuntu 3.11 and lower). What is your
> OS?
Debian, both oldstable and stable do not have a mock.
I do have unittest installed on both systems.
from unittest import mock
work on both of them.
> 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
Yes, seems not very portable, lets use either unittest.mock or the one
that comes with roundup.
Thanks
Ralf
--
Dr. Ralf Schlatterbeck Tel: +43/2243/26465-16
Open Source Consulting www: www.runtux.com
Reichergasse 131, A-3411 Weidling email: office@runtux.com
|
|||
| msg7668 | Author: [hidden] (rouilj) | Date: 2022-11-23 20:33 | |
Hi Ralf: In message <20221123172044.gxvyr74nuw5klbfy@runtux.com>, Ralf Schlatterbeck writes: >On Wed, Nov 23, 2022 at 03:25:05PM +0000, John Rouillard wrote: >> >> try: >> import mock >> except ImportError: >> import unittest.mock as mock > >OK, you know that roundup has its own mock module in >roundup/test/mocknull.py? Does this do the same thing? It has no patch method so I claim it does not do the same thing. >> I have no error of that type in CI (ubuntu 3.11 and lower). What is your >> OS? > >Debian, both oldstable and stable do not have a mock. >I do have unittest installed on both systems. > > from unittest import mock > >work on both of them. Ok. >> 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 > >Yes, seems not very portable, lets use either unittest.mock or the one >that comes with roundup. unittest.mock isn't in 2.7. So I maybe: try: import unittest.mock as mock except ImportError: import mock Make the 3.x the default path and 2.x the compatibility exception. |
|||
| msg7671 | Author: [hidden] (schlatterbeck) | Date: 2022-11-24 09:36 | |
On Wed, Nov 23, 2022 at 08:33:03PM +0000, John Rouillard wrote: > unittest.mock isn't in 2.7. So I maybe: > > try: > import unittest.mock as mock > except ImportError: > import mock > > Make the 3.x the default path and 2.x the compatibility exception. I've tested this on the systems available to me: - Debian oldstable python2.7.16 - Debian oldstable python3.7.3 - Debian stable python3.9.2 - custom installed python3.10.5 and pushed the fix. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-11-24 15:08:06 | rouilj | set | status: open -> fixed type: crash resolution: fixed |
| 2022-11-24 09:36:20 | schlatterbeck | set | messages: + msg7671 |
| 2022-11-23 20:33:03 | rouilj | set | messages: + msg7668 |
| 2022-11-23 17:20:46 | schlatterbeck | set | messages: + msg7667 |
| 2022-11-23 15:25:12 | rouilj | set | status: new -> open |
| 2022-11-23 15:25:05 | rouilj | set | messages: + msg7666 |
| 2022-11-23 06:34:01 | schlatterbeck | create | |