From 85e1b3a9ac9a2c60fc1a9688d73ed96fb8490cef Mon Sep 17 00:00:00 2001 From: Kirill Pinchuk Date: Sun, 19 Sep 2021 00:19:51 +0300 Subject: [PATCH] Enable reflection --- pytest_flask_sqlalchemy/fixtures.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pytest_flask_sqlalchemy/fixtures.py b/pytest_flask_sqlalchemy/fixtures.py index 0396bd6..6afb4fd 100644 --- a/pytest_flask_sqlalchemy/fixtures.py +++ b/pytest_flask_sqlalchemy/fixtures.py @@ -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 @@ -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)