Karthikeyan Singaravelan <[email protected]> added the comment:
For a simple experiment raising an exception I can see two tests failing in
test suite that have the pattern of having an autospec which is a mock object.
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 720f682efb..d33c7899a1 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2612,6 +2612,9 @@ def create_autospec(spec, spec_set=False, instance=False,
_parent=None,
# interpreted as a list of strings
spec = type(spec)
+ if _is_instance_mock(spec):
+ 1 / 0
+
is_type = isinstance(spec, type)
is_async_func = _is_async_func(spec)
_kwargs = {'spec': spec}
./python -m unittest Lib.unittest.test.testmock
....................................................................................................................................................E..............................................................................................................................................................E...........................................................................................................................................................................................
======================================================================
ERROR: test_bool_not_called_when_passing_spec_arg
(unittest.test.testmock.testmock.MockTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/cpython/Lib/unittest/test/testmock/testmock.py", line 2180, in
test_bool_not_called_when_passing_spec_arg
with unittest.mock.patch.object(obj, 'obj_with_bool_func', autospec=True):
pass
File "/root/cpython/Lib/unittest/mock.py", line 1503, in __enter__
new = create_autospec(autospec, spec_set=spec_set,
File "/root/cpython/Lib/unittest/mock.py", line 2616, in create_autospec
1 / 0
ZeroDivisionError: division by zero
======================================================================
ERROR: test_create_autospec_awaitable_class
(unittest.test.testmock.testasync.AsyncAutospecTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/cpython/Lib/unittest/test/testmock/testasync.py", line 204, in
test_create_autospec_awaitable_class
self.assertIsInstance(create_autospec(awaitable_mock), AsyncMock)
File "/root/cpython/Lib/unittest/mock.py", line 2616, in create_autospec
1 / 0
ZeroDivisionError: division by zero
----------------------------------------------------------------------
Ran 495 tests in 2.039s
FAILED (errors=2)
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43478>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com