Types in examples
Some of the example code blocks in the README.md are unclear because either some identifiers are not defined in the code block or the types are not explicit.
For example in [this](https://github.com/dbfixtures/pytest-postgresql?tab=readme-ov-file#using-sqlalchemy-to-initialise-basic-database-state) code block:
```
def load_database(**kwargs):
connection = f"postgresql+psycopg2://{kwargs['user']}:@{kwargs['host']}:{kwargs['port']}/{kwargs['dbname']}"
engine = create_engine(connection)
Base.metadata.create_all(engine)
session = scoped_session(sessionmaker(bind=engine))
# add things to session
session.commit()
postgresql_proc = factories.postgresql_proc(load=[load_database])
postgresql = factories.postgresql('postgresql_proc') # still need to check if this is actually needed or not
@pytest.fixture
def dbsession(postgresql): # FIXME what type hint here?
connection = f'postgresql+psycopg2://{postgresql.info.user}:@{postgresql.info.host}:{postgresql.info.port}/{postgresql.info.dbname}'
engine = create_engine(connection)
session = scoped_session(sessionmaker(bind=engine))
yield session
# 'Base.metadata.drop_all(engine)' here specifically does not work. It is also not needed. If you leave out the session.close()
# all the tests still run, but you get a warning/error at the end of the tests.
session.close()
```
What would be a proper type hint for the `postgresql` parameter?
Also, some more imports could make it more clear.
4 条评论