def begin(self, unloading=False): """Begin loading data - creates and stores a connection with engine.connect() if an engine was passed - binds the connection or engine to fixture's internal session - uses an unbound internal session if no engine or connection was passed in """ if not unloading: # ...then we are loading, so let's *lazily* # clean up after a previous setup/teardown Session.remove() if self.connection is None and self.engine is None: if self.session: self.engine = self.session.bind # might be None if self.engine is not None and self.connection is None: self.connection = self.engine.connect() if self.session is None: if self.connection: self.session = self.Session(bind=self.connection) else: self.session = self.Session(bind=None) DBLoadableFixture.begin(self, unloading=unloading)
def begin(self, unloading=False): if self.session is None and self.scoped_session is None: raise UninitializedError( "%s must be assigned either a session or session_context" % (self.__class__.__name__)) if self.scoped_session is not None: self.session = self.scoped_session() #if self.session is None: # self.session = self.scoped_session() if not self.connection and self.session.bind is not None: self.connection = self.session.bind.connect() DBLoadableFixture.begin(self, unloading=unloading)