0

My Model is as follows, this model is defined in a file called tool_model.py, Hence the creation using tool_model.SQLModel.metadata.create_all(engine)

class Tool(SQLModel, table=True):
    __tablename__='tools'
    __table_args__ = {'schema': 'rna'}


    id: Optional[int] = Field(default=None, primary_key=True)
    tool_name: str = Field(sa_column=Column("tool_name", VARCHAR(500), nullable=False))
    tool_description: str = Field(
        sa_column=Column("tool_description", VARCHAR(1000), nullable=False)
    )

This seems to be working fine, but when I try to create unit test for the same and try to create the models in fixture

conftest.py

@pytest.fixture(name="session",scope="module")
def session_fixture():
    engine = create_engine(
        "sqlite:///./test.db", connect_args={"check_same_thread": False}, poolclass=StaticPool
    )
    SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
    tool_model.SQLModel.metadata.create_all(engine)

it is giving me the following error

E sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unknown database "rna"
E [SQL: PRAGMA "rna".table_info("tools")]
E (Background on this error at: https://sqlalche.me/e/14/e3q8)
code_10
  • 155
  • 1
  • 2
  • 10
  • 1
    [Does this answer your question?](https://stackoverflow.com/q/2685899/5320906) (the most recent answer looks like it might be useful). – snakecharmerb Jan 06 '23 at 19:04

0 Answers0