我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用factory.SubFactory()。
def projects(self, create, extracted, **kwargs): if not extracted: project_factory = factory.SubFactory(ProjectFactory).get_factory() self.projects.add(project_factory()) elif extracted: for project in extracted: self.projects.add(project)
def moderators(self, create, extracted, **kwargs): if not extracted: user_factory = factory.SubFactory(USER_FACTORY).get_factory() self.moderators.add(user_factory()) return if extracted: for user in extracted: self.moderators.add(user)