Skip to content

Instantly share code, notes, and snippets.

@diyan
Last active December 25, 2015 06:39
Show Gist options
  • Save diyan/6933502 to your computer and use it in GitHub Desktop.
Save diyan/6933502 to your computer and use it in GitHub Desktop.
class BaseFactory(SQLAlchemyModelFactory):
ABSTRACT_FACTORY = True
@classmethod
def get_factory_session(cls):
if not getattr(cls, '_LAZY_FACTORY_SESSION', None):
session = open_db('test')
Base.metadata.create_all(session.bind)
cls._LAZY_FACTORY_SESSION = session
return cls._LAZY_FACTORY_SESSION
@classmethod
def _setup_next_sequence(cls, *args, **kwargs):
SQLAlchemyModelFactory.FACTORY_FOR = cls.FACTORY_FOR
SQLAlchemyModelFactory.FACTORY_SESSION = BaseFactory.get_factory_session()
return SQLAlchemyModelFactory._setup_next_sequence(*args, **kwargs)
@classmethod
def _create(cls, target_class, *args, **kwargs):
return SQLAlchemyModelFactory._create(target_class, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment