Roundup Tracker - Issues

Issue 2551296

classification
from mock import Mock?
Type: behavior Severity: normal
Components: Test Versions: devel
process
Status: fixed fixed
:
: rouilj : rouilj, schlatterbeck
Priority: normal :

Created on 2023-10-24 10:35 by schlatterbeck, last changed 2023-10-25 12:19 by rouilj.

Messages
msg7848 Author: [hidden] (schlatterbeck) Date: 2023-10-24 10:35
test/test_hyperdbvals.py has

from mock import Mock

in the commit
changeset:   7212:76a21cf791b9

Where do I get this from?
My standard python 3.11.2 (debian stable aka bookworm) doesn't have it:

>>> from mock import Mock
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mock'


But it seems to be in unittest:

>>> from unittest.mock import Mock
>>> 

But I'm unsure if this is the same thing.
msg7849 Author: [hidden] (rouilj) Date: 2023-10-24 13:24
Hi Ralf:

In message <1698143743.33.0.829120522093.issue2551296@roundup.psfhosted.org>,
Ralf Schlatterbeck writes:
>New submission from Ralf Schlatterbeck:
>
>test/test_hyperdbvals.py has
>
>from mock import Mock
>
>in the commit
>changeset:   7212:76a21cf791b9
>
>Where do I get this from?
>My standard python 3.11.2 (debian stable aka bookworm) doesn't have it:
[...]
>But it seems to be in unittest:
>
>>>> from unittest.mock import Mock
>>>> 
>
>But I'm unsure if this is the same thing.

For python 3.6 (debian 18.04) mock is 

  /usr/lib/python3/dist-packages/mock/mock.py

and starts:

   # mock 1.0.1
   # http://www.voidspace.org.uk/python/mock/
   #
   # Copyright (c) 2007-2013, Michael Foord & the mock team

and diffing it against /usr/lib/python3.6/unittest/mock.py which starts:

   # mock.py
   # Test tools for mocking and patching.
   # Maintained by Michael Foord
   # Backport for other versions of Python available from
   # https://pypi.org/project/mock

makes it look like unittest/mock.py is just a different version of
mock/mock.py.

However there is no mock in unittest under my python2.7.

I have changed that import to read:

try:
   from unittest.mock import Mock
except ImportError:
   # python 2.7
   from mock import Mock

and successfully run that test module under python2.7 and 3.6.

Committed in changeset:   7670:a28ea83ace86
msg7850 Author: [hidden] (schlatterbeck) Date: 2023-10-25 09:00
Thanks for fixing it so quickly.
I've added some lines to an existing extended link query test that I was trying to get running.
msg7851 Author: [hidden] (rouilj) Date: 2023-10-25 12:19
Hi Ralf:

In message <1698224409.67.0.989451693562.issue2551296@roundup.psfhosted.org>,
Ralf Schlatterbeck writes:
>Ralf Schlatterbeck added the comment:
>
>Thanks for fixing it so quickly.
>I've added some lines to an existing extended link query test that I
>was trying to get running.

Cool. I have pulled your change. Thanks for the heads up.
History
Date User Action Args
2023-10-25 12:19:05rouiljsetmessages: + msg7851
2023-10-25 09:00:09schlatterbecksetmessages: + msg7850
2023-10-24 13:26:49rouiljsetassignee: rouilj
resolution: fixed
2023-10-24 13:24:27rouiljsetstatus: new -> fixed
messages: + msg7849
2023-10-24 10:35:43schlatterbeckcreate