Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle warnings related to connection reset agent #38

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions pytest_flask_sqlalchemy/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ def _transaction(request, _db, mocker):
# Make sure the session, connection, and transaction can't be closed by accident in
# the codebase
connection.force_close = connection.close
transaction.force_rollback = transaction.rollback

connection.close = lambda: None
transaction.rollback = lambda: None
session.close = lambda: None

# Begin a nested transaction (any new transactions created in the codebase
Expand Down Expand Up @@ -74,13 +72,13 @@ def rehydrate_object(session, obj):

@request.addfinalizer
def teardown_transaction():
# Delete the session
session.remove()

# Rollback the transaction and return the connection to the pool
transaction.force_rollback()
transaction.rollback()
connection.force_close()

# Delete the session
session.remove()

return connection, transaction, session


Expand All @@ -97,10 +95,15 @@ def _engine(pytestconfig, request, _transaction, mocker):

engine.connect.return_value = connection

# Threadlocal engine strategies were deprecated in SQLAlchemy 1.3, which
# resulted in contextual_connect becoming a private method. See:
# Threadlocal engine strategies were deprecated in SQLAlchemy 1.3 and
# fully removed in 1.4. The deprecation resulted in contextual_connect
# becoming a private method. See:
# https://docs.sqlalchemy.org/en/latest/changelog/migration_13.html
if version.parse(sa.__version__) < version.parse('1.3'):
sa_version = version.parse(sa.__version__)
sa_version = version.parse(sa_version.base_version)
if sa_version >= version.parse('1.4'):
pass
elif sa_version < version.parse('1.3'):
engine.contextual_connect.return_value = connection
else:
engine._contextual_connect.return_value = connection
Expand Down