0
我試圖模擬都bulk_create
和save
幹運行。 我這在本質上並創建如下代碼:嘲笑Model.objects.bulk_create和Model.save()
@mock.patch.object(SomeModel.objects, 'bulk_create')
@mock.patch.object(SomeModel, 'save')
def a_dry_run(mocked_bulk_create, mocked_save):
def print_bulk(obj_list):
print 'doing bulk_create'
for obj in obj_list:
print obj
def print_save(instance):
print 'doing save'
print instance
mocked_bulk_create.side_effect = print_bulk
mocked_bulk_create.return_value = True
mocked_save.side_effect = print_save
mocked_save.return_value = True
的問題是,當我做bulk_create
而不是print_bulk
它執行print_save
。我該如何解決這個問題,或者有一個更清潔的方法來做到這一點?