Skip to content
Discussion options

You must be logged in to vote

The key was passing connection to the session maker, and use the factory class directly created by the scoped_session. Also using the context manager with app.app_context()

What I was doing wrong was creating another instance from the factory class.

@pytest.fixture(scope="module")
def db_session(db):
    """Creates a new database session for a test."""
    print(f"Pytest connection is {db.engine}")
    connection = db.engine.connect()
    transaction = connection.begin()
    db.session = scoped_session(
        session_factory=sessionmaker(
            bind=connection,
        )
    )

    yield db.session

    transaction.rollback()
    db.session.rollback()
    db.session.remove()
    db.

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@supreme-core
Comment options

@RonnyPfannschmidt
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by supreme-core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1324 on April 05, 2024 17:41.