是否可以在不创建两个Factory对象的情况下设置SubFactory的值?
例如,我有两个工厂;
class UserFactory(factory.DjangoModelFactory):
FACTORY_FOR = 'mysite.user'
name = "Mark"
class MyFactory(factory.DjangoModelFactory):
FACTORY_FOR = 'mysite.myfactory'
user = factory.SubFactory(UserFactory)
我想创建MyFactory()
并同时设置user.name
的值。
您是否必须先创建user = UserFactory.create(name="John")
,还是可以从args到MyFactory()
一行完成?
在测试的那一刻,我得到了以下内容;
def setUp(self):
user = factories.UserFactory(name="John")
myfactory = factories.MyFactory(user=user)
答案 0 :(得分:3)