From 598f2f7e557073f29563d4d567f43931fc03013f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 3 Mar 2020 16:03:39 -0500 Subject: Don't import provision.py unconditionally Removed the imports for provision.py from each dialect and instead added a call in the central provision.py to a new dialect level method load_provisioning(). The provisioning registry works in the same way, so an existing dialect that is using the provision.py system right now by importing it as part of the package will still continue to function. However, to avoid pulling in the testing package when the dialect is used in a non-testing context, the new hook may be used. Also removed a module-level dependency of the testing framework on the orm package. Revised an internal change to the test system added as a result of :ticket:`5085` where a testing-related module per dialect would be loaded unconditionally upon making use of that dialect, pulling in SQLAlchemy's testing framework as well as the ORM into the module import space. This would only impact initial startup time and memory to a modest extent, however it's best that these additional modules aren't reverse-dependent on straight Core usage. Fixes: #5180 Change-Id: I6355601da5f6f44d85a2bbc3acb5928559942b9c --- lib/sqlalchemy/testing/assertions.py | 3 ++- lib/sqlalchemy/testing/provision.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/testing') diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py index c97202516..07a70bf6c 100644 --- a/lib/sqlalchemy/testing/assertions.py +++ b/lib/sqlalchemy/testing/assertions.py @@ -19,7 +19,6 @@ from . import mock from .exclusions import db_spec from .util import fail from .. import exc as sa_exc -from .. import orm from .. import schema from .. import types as sqltypes from .. import util @@ -386,6 +385,8 @@ class AssertsCompiledSQL(object): if render_postcompile: compile_kwargs["render_postcompile"] = True + from sqlalchemy import orm + if isinstance(clause, orm.Query): context = clause._compile_context() context.statement.use_labels = True diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py index 6e2e1ccf5..543d91a53 100644 --- a/lib/sqlalchemy/testing/provision.py +++ b/lib/sqlalchemy/testing/provision.py @@ -6,7 +6,6 @@ from . import engines from ..engine import url as sa_url from ..util import compat - log = logging.getLogger(__name__) FOLLOWER_IDENT = None @@ -51,7 +50,9 @@ def setup_config(db_url, options, file_config, follower_ident): # load the dialect, which should also have it set up its provision # hooks - sa_url.make_url(db_url).get_dialect() + dialect = sa_url.make_url(db_url).get_dialect() + dialect.load_provisioning() + if follower_ident: db_url = follower_url_from_main(db_url, follower_ident) db_opts = {} -- cgit v1.2.1