Skip to content

Commit

Permalink
Enable reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
cybergrind authored and fgregg committed Sep 27, 2021
1 parent ea5c5ee commit 85e1b3a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pytest_flask_sqlalchemy/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def _engine(pytestconfig, request, _transaction, mocker):

# Make sure that any attempts to call `connect()` simply return a
# reference to the open connection

engine = mocker.MagicMock(spec=sa.engine.Engine)

engine.connect.return_value = connection
Expand All @@ -105,6 +106,12 @@ def _engine(pytestconfig, request, _transaction, mocker):
elif version.parse(sa.__version__) < version.parse('1.4'):
engine._contextual_connect.return_value = connection

# Calls to execution_options should return this mocked engine.
engine.execution_options.return_value = engine

if version.parse(sa.__version__) >= version.parse('1.4'):
sa.inspection._registrars[mocker.MagicMock] = sa.engine.Inspector._engine_insp

# References to `Engine.dialect` should redirect to the Connection (this
# is primarily useful for the `autoload` flag in SQLAlchemy, which references
# the Engine dialect to reflect tables)
Expand Down

0 comments on commit 85e1b3a

Please sign in to comment.