Skip to content

Commit

Permalink
don't try subclassing magicmock
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed Sep 27, 2021
1 parent 347f35f commit 5a3a799
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pytest_flask_sqlalchemy/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ def _engine(pytestconfig, request, _transaction, mocker):

# Make sure that any attempts to call `connect()` simply return a
# reference to the open connection
class EngineMock(mocker.MagicMock):
pass

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

engine.connect.return_value = connection

Expand All @@ -109,10 +107,10 @@ class EngineMock(mocker.MagicMock):
engine._contextual_connect.return_value = connection

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

if version.parse(sa.__version__) >= version.parse('1.4'):
sa.inspection._registrars[EngineMock] = sa.engine.Inspector._engine_insp
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
Expand Down

0 comments on commit 5a3a799

Please sign in to comment.