From 3231e281efb2f36dd0dbd628efcd684175064386 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 14 Aug 2020 12:07:14 -0400 Subject: Provision on different drivers dynamically We want TOX_POSTGRESQL and similar to be the fixed variable that is configured from CI environment. These variables should refer to database servers but individual drivers like asyncpg mysqlconnector etc. should come from local tox.ini. add a new system to generate per-driver URLs from a simple list of hostname-based URLs delivered from CI environment. Change-Id: I4267b4a70742765388c7e7c4432c1da9d9adece2 --- lib/sqlalchemy/testing/plugin/plugin_base.py | 25 +++++++++++++++++++++++-- lib/sqlalchemy/testing/plugin/pytestplugin.py | 16 ++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'lib/sqlalchemy/testing/plugin') diff --git a/lib/sqlalchemy/testing/plugin/plugin_base.py b/lib/sqlalchemy/testing/plugin/plugin_base.py index 49ff0f975..b5f2a3e0b 100644 --- a/lib/sqlalchemy/testing/plugin/plugin_base.py +++ b/lib/sqlalchemy/testing/plugin/plugin_base.py @@ -17,10 +17,14 @@ is pytest. from __future__ import absolute_import import abc +import logging import re import sys +log = logging.getLogger("sqlalchemy.testing.plugin_base") + + py3k = sys.version_info >= (3, 0) if py3k: @@ -90,6 +94,15 @@ def setup_options(make_option): dest="dburi", help="Database uri. Multiple OK, " "first one is run by default.", ) + make_option( + "--dbdriver", + action="append", + type="string", + dest="dbdriver", + help="Additional database drivers to include in tests. " + "These are linked to the existing database URLs by the " + "provisioning system.", + ) make_option( "--dropfirst", action="store_true", @@ -350,6 +363,7 @@ def _init_symbols(options, file_config): @post def _engine_uri(options, file_config): + from sqlalchemy.testing import config from sqlalchemy import testing from sqlalchemy.testing import provision @@ -359,6 +373,8 @@ def _engine_uri(options, file_config): else: db_urls = [] + extra_drivers = options.dbdriver or [] + if options.db: for db_token in options.db: for db in re.split(r"[,\s]+", db_token): @@ -374,7 +390,11 @@ def _engine_uri(options, file_config): db_urls.append(file_config.get("db", "default")) config._current = None - for db_url in db_urls: + + expanded_urls = list(provision.generate_db_urls(db_urls, extra_drivers)) + + for db_url in expanded_urls: + log.info("Adding database URL: %s", db_url) if options.write_idents and provision.FOLLOWER_IDENT: # != 'master': with open(options.write_idents, "a") as file_: @@ -596,7 +616,8 @@ def stop_test_class(cls): def _restore_engine(): - config._current.reset(testing) + if config._current: + config._current.reset(testing) def final_process_cleanup(): diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py index 3df239afa..1b2bbca23 100644 --- a/lib/sqlalchemy/testing/plugin/pytestplugin.py +++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py @@ -89,9 +89,9 @@ def pytest_addoption(parser): def pytest_configure(config): - if hasattr(config, "slaveinput"): - plugin_base.restore_important_follower_config(config.slaveinput) - plugin_base.configure_follower(config.slaveinput["follower_ident"]) + if hasattr(config, "workerinput"): + plugin_base.restore_important_follower_config(config.workerinput) + plugin_base.configure_follower(config.workerinput["follower_ident"]) else: if config.option.write_idents and os.path.exists( config.option.write_idents @@ -162,20 +162,20 @@ if has_xdist: import uuid def pytest_configure_node(node): - # the master for each node fills slaveinput dictionary + # the master for each node fills workerinput dictionary # which pytest-xdist will transfer to the subprocess - plugin_base.memoize_important_follower_config(node.slaveinput) + plugin_base.memoize_important_follower_config(node.workerinput) - node.slaveinput["follower_ident"] = "test_%s" % uuid.uuid4().hex[0:12] + node.workerinput["follower_ident"] = "test_%s" % uuid.uuid4().hex[0:12] from sqlalchemy.testing import provision - provision.create_follower_db(node.slaveinput["follower_ident"]) + provision.create_follower_db(node.workerinput["follower_ident"]) def pytest_testnodedown(node, error): from sqlalchemy.testing import provision - provision.drop_follower_db(node.slaveinput["follower_ident"]) + provision.drop_follower_db(node.workerinput["follower_ident"]) def pytest_collection_modifyitems(session, config, items): -- cgit v1.2.1