Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Hello, thanks for the work you do!
My issue: Updating from 3.12.3 to 3.12.4 breaks many elements in my test suite. We use thename= argument to better understand log messages once a test with many objects fails.
This works with 3.12.3, but crashes with 3.12.4. The issue might have been introduced with this fix:23ba96e
Code example
Fileautospec_test.py:
importunittestfromunittest.mockimportcreate_autospecclassX: ...classTestX(unittest.TestCase):deftest_x(self):mock=create_autospec(X,spec_set=True,name="X")if__name__=="__main__":unittest.main()
Observed behavior
python 3.12.3
python autospec_test.py.----------------------------------------------------------------------Ran 1 test in 0.001sOKpython 3.12.4
python autospec_test.pyE======================================================================ERROR:test_x (__main__.TestX.test_x)----------------------------------------------------------------------Traceback (most recent call last): File".../autospec_test.py", line10, intest_x mock= create_autospec(X,spec_set=True,name="X")^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File"/usr/local/lib/python3.12/unittest/mock.py", line2823, increate_autospec mock.configure_mock(**kwargs) File"/usr/local/lib/python3.12/unittest/mock.py", line650, inconfigure_mocksetattr(obj, final, val) File"/usr/local/lib/python3.12/unittest/mock.py", line774, in__setattr__raiseAttributeError("Mock object has no attribute '%s'"% name)AttributeError:Mock object has no attribute 'name'----------------------------------------------------------------------Ran 1 test in 0.003sFAILED (errors=1)
CPython versions tested on:
3.12
Operating systems tested on:
Linux, (CI pipelines failed on windows, too – didn't test this example, though.)