Author xtreak
Recipients cjw296, gregory.p.smith, lisroach, mariocj89, michael.foord, msuozzo, xtreak
Date 2021-03-15.17:49:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615830542.18.0.468432256577.issue43478@roundup.psfhosted.org>
In-reply-to
Content
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)
History
Date User Action Args
2021-03-15 17:49:02xtreaksetrecipients: + xtreak, gregory.p.smith, cjw296, michael.foord, lisroach, mariocj89, msuozzo
2021-03-15 17:49:02xtreaksetmessageid: <1615830542.18.0.468432256577.issue43478@roundup.psfhosted.org>
2021-03-15 17:49:02xtreaklinkissue43478 messages
2021-03-15 17:49:02xtreakcreate