[New-bugs-announce] [issue42586] unittest.mock.Mock spec can't be array/ndarray in Python 3.9

Valeriu Predoi report at bugs.python.org
Mon Dec 7 08:31:34 EST 2020

New submission from Valeriu Predoi <valeriu.predoi at gmail.com>:

Hey guys, the new unittest.mock.Mock for Python 3.9 can not accept a spec arg if it is a numpy array, it'll accept all other types but not ndarray, have a look at this quick minimal code:

import numpy as np

from unittest import mock as mg

ob = mg.Mock(spec=[4, 4])
print("spec is list, mock is", ob)

ob = mg.Mock(spec=["4", "4"])
print("spec is list of str, mock is", ob)

ob = mg.Mock(spec=(4, 4))
print("spec is tuple, mock is", ob)

ob = mg.Mock(spec="cow")
print("spec is string, mock is", ob)

ob = mg.Mock(spec=22)
print("spec is int, mock is", ob)

ob = mg.Mock(spec=np.array([4, 4]))
print("spec is ndarray, mock is", ob)

python  3.9.0 h2a148a8_4_cpython    conda-forge
pytest-mock 3.3.1  pypi_0    pypi

Is this intended or it's a buggy-bug?

Cheers muchly! V

components: Tests
messages: 382634
nosy: valeriupredoi
priority: normal
severity: normal
status: open
title: unittest.mock.Mock spec can't be array/ndarray in Python 3.9
type: behavior
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list