I am working on a Pyramid application with SQLAlchemy as an ORM. I am trying to test a model using a class method:
I use factory_boy for testing, and here is how I try to set up my factory testing:
import factory from factory.alchemy import SQLAlchemyModelFactory from sqlalchemy.orm import scoped_session, sessionmaker from zk.model.meta import Base from zk.model.role import Role session = scoped_session(sessionmaker()) engine = create_engine('sqlite://') session.configure(bind=engine) Base.metadata.create_all(engine) class RoleFactory(SQLAlchemyModelFactory): FACTORY_FOR = Role FACTORY_SESSION = session
However, when I try to call RoleFactory.find_all() in the test, I get the error message: E UnboundExecutionError: could not find the binding configured on mapper Mapper | Role | role, SQL expression, or this session
I tried monkeypatching meta and replaced this global session with my session, but then I get this error: E AttributeError: object type 'RoleFactory' does not have attribute 'find_all'
I tried calling RoleFactory.FACTORY_FOR.find_all() , but then got the same UnboundExecutionError.
Do I need to do something for factory_boy to find out about the class method?
python class-method sqlalchemy factory-boy
pfctdayelise
source share