summaryrefslogtreecommitdiff
path: root/tests/test_environment.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-03-04 16:42:30 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2017-03-04 17:12:03 -0500
commitadf0a7d1ea881907bdf546778dae72e6ac0a3027 (patch)
tree8de4f7aed5f289459564bda20ccd7bc40b2f28b6 /tests/test_environment.py
parent5191bc1e65cd2e686f37c0e579a394b4c2b2c54a (diff)
downloadalembic-adf0a7d1ea881907bdf546778dae72e6ac0a3027.tar.gz
Warn on non-Connection present and accommodate for Engine
A warning is emitted when an object that's not a :class:`~sqlalchemy.engine.Connection` is passed to :meth:`.EnvironmentContext.configure`. For the case of a :class:`~sqlalchemy.engine.Engine` passed, the check for "in transaction" introduced in version 0.9.0 has been relaxed to work in the case of an attribute error, as some users appear to be passing an :class:`~sqlalchemy.engine.Engine` and not a :class:`~sqlalchemy.engine.Connection`. Change-Id: I95ef38955c00511d3055362a03284fb91677595f Fixes: #419
Diffstat (limited to 'tests/test_environment.py')
-rw-r--r--tests/test_environment.py48
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/test_environment.py b/tests/test_environment.py
index cb8a0a2..42ff328 100644
--- a/tests/test_environment.py
+++ b/tests/test_environment.py
@@ -4,9 +4,10 @@ from alembic.script import ScriptDirectory
from alembic.environment import EnvironmentContext
from alembic.migration import MigrationContext
from alembic.testing.fixtures import TestBase
-from alembic.testing.mock import Mock, call
+from alembic.testing.mock import Mock, call, MagicMock
from alembic.testing.env import _no_sql_testing_config, \
- staging_env, clear_staging_env
+ staging_env, clear_staging_env, write_script, _sqlite_file_db
+from alembic.testing.assertions import expect_warnings
from alembic.testing import eq_, is_
@@ -74,3 +75,46 @@ class EnvironmentTest(TestBase):
ctx = MigrationContext(ctx.dialect, None, {})
is_(ctx.config, None)
+
+ def test_warning_on_passing_engine(self):
+ env = self._fixture()
+
+ engine = _sqlite_file_db()
+
+ a_rev = 'arev'
+ env.script.generate_revision(a_rev, "revision a", refresh=True)
+ write_script(env.script, a_rev, """\
+"Rev A"
+revision = '%s'
+down_revision = None
+
+from alembic import op
+
+
+def upgrade():
+ pass
+
+
+def downgrade():
+ pass
+
+""" % a_rev)
+ migration_fn = MagicMock()
+
+ def upgrade(rev, context):
+ migration_fn(rev, context)
+ return env.script._upgrade_revs(a_rev, rev)
+
+ with expect_warnings(
+ r"'connection' argument to configure\(\) is "
+ r"expected to be a sqlalchemy.engine.Connection "):
+ env.configure(
+ connection=engine, fn=upgrade,
+ transactional_ddl=False)
+
+ env.run_migrations()
+
+ eq_(
+ migration_fn.mock_calls,
+ [call((), env._migration_context)]
+ )