0
2 개의 객체를 패치해야하는 곳에서 UT를 작성하고 있습니다.2 개의 객체를 패치 할 때, 두 번째는 첫 번째 패치 값을 반환합니다.
@patch('mypackage.models.db_models.MongoClient',
return_value={})
@patch('mypackage.models.db_models.GridFS')
def test_file_in_db(self, mock_mongoclient, mock_gridfs):
print "*"*80
print mock_gridfs
print mock_gridfs.return_value
print "*"*80
mock_gridfs.return_value.new_file.return_value = {}
이 오류 제공합니다
----------------------------------------------------------------------
Traceback (most recent call last):
File "/venv/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched
return func(*args, **keywargs)
File "/tests/models/test_db_models.py", line 29, in test_file_in_db
mock_gridfs.return_value.new_file.return_value = {}
AttributeError: 'dict' object has no attribute 'new_file'
-------------------- >> begin captured stdout << ---------------------
********************************************************************************
<MagicMock name='MongoClient' id='4385486992'>
{}
********************************************************************************
--------------------- >> end captured stdout << ----------------------
내가 두 번째 인수를 액세스하고, mock_gridfs
이 왜 MongoClient
에 대한 Mock
개체를 반환 의미?