diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-04 15:43:16 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-04 16:16:55 -0400 |
commit | 9b637eaa15f8c44c7bd2841b2179598101a0fcd9 (patch) | |
tree | 371ff924145ae48728dc0253d595224a4a694ef7 | |
parent | 54cdda032ea59789be15972ed0529f71fd4f0214 (diff) | |
download | sqlalchemy-allow_multi_backends.tar.gz |
Allow multiple versions of single backendallow_multi_backends
Improve screen output to illustrate which server version is
running for a particular database config, and additionally
allow full overriding for the backend-specific targets in
tox.ini via environment variables, so that CI can inject
multiple server urls for a particular database such as MySQL/MariaDB.
Change-Id: Ibf443bb9fb82e4563efd1bb66058fa9989aa2fda
-rw-r--r-- | lib/sqlalchemy/testing/config.py | 18 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/plugin/plugin_base.py | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/provision.py | 1 | ||||
-rw-r--r-- | tox.ini | 16 |
4 files changed, 25 insertions, 17 deletions
diff --git a/lib/sqlalchemy/testing/config.py b/lib/sqlalchemy/testing/config.py index 64be3ac74..73d8a7de8 100644 --- a/lib/sqlalchemy/testing/config.py +++ b/lib/sqlalchemy/testing/config.py @@ -24,6 +24,7 @@ except ImportError: class Config(object): def __init__(self, db, db_opts, options, file_config): + self._set_name(db) self.db = db self.db_opts = db_opts self.options = options @@ -32,7 +33,14 @@ class Config(object): self.test_schema_2 = "test_schema_2" _stack = collections.deque() - _configs = {} + _configs = set() + + def _set_name(self, db): + if db.dialect.server_version_info: + svi = ".".join(str(tok) for tok in db.dialect.server_version_info) + self.name = "%s+%s_[%s]" % (db.name, db.driver, svi) + else: + self.name = "%s+%s" % (db.name, db.driver) @classmethod def register(cls, db, db_opts, options, file_config): @@ -42,10 +50,7 @@ class Config(object): gets set as the "_current". """ cfg = Config(db, db_opts, options, file_config) - - cls._configs[cfg.db.name] = cfg - cls._configs[(cfg.db.name, cfg.db.dialect)] = cfg - cls._configs[cfg.db] = cfg + cls._configs.add(cfg) return cfg @classmethod @@ -80,8 +85,7 @@ class Config(object): @classmethod def all_configs(cls): - for cfg in set(cls._configs.values()): - yield cfg + return cls._configs @classmethod def all_dbs(cls): diff --git a/lib/sqlalchemy/testing/plugin/plugin_base.py b/lib/sqlalchemy/testing/plugin/plugin_base.py index 996cf4582..e01fa9bd0 100644 --- a/lib/sqlalchemy/testing/plugin/plugin_base.py +++ b/lib/sqlalchemy/testing/plugin/plugin_base.py @@ -409,12 +409,12 @@ def want_method(cls, fn): def generate_sub_tests(cls, module): if getattr(cls, '__backend__', False): for cfg in _possible_configs_for_cls(cls): - name = "%s_%s_%s" % (cls.__name__, cfg.db.name, cfg.db.driver) + name = "%s_%s" % (cls.__name__, cfg.name) subcls = type( name, (cls, ), { - "__only_on__": ("%s+%s" % (cfg.db.name, cfg.db.driver)), + "__only_on_config__": cfg } ) setattr(module, name, subcls) @@ -489,6 +489,9 @@ def _possible_configs_for_cls(cls, reasons=None): if not spec(config_obj): all_configs.remove(config_obj) + if getattr(cls, '__only_on_config__', None): + all_configs.intersection_update([cls.__only_on_config__]) + if hasattr(cls, '__requires__'): requirements = config.requirements for config_obj in list(all_configs): diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py index 83b6115fe..9fb9eae8d 100644 --- a/lib/sqlalchemy/testing/provision.py +++ b/lib/sqlalchemy/testing/provision.py @@ -57,6 +57,7 @@ def setup_config(db_url, options, file_config, follower_ident): eng = engines.testing_engine(db_url, db_opts) _post_configure_engine(db_url, eng, follower_ident) eng.connect().close() + cfg = config.Config.register(eng, db_opts, options, file_config) if follower_ident: _configure_follower(cfg, follower_ident) @@ -47,21 +47,21 @@ setenv= PYTHONNOUSERSITE=1 BASECOMMAND=python -m pytest - WORKERS=-n4 - oracle: WORKERS=-n2 + WORKERS={env:WORKERS:-n4} + oracle: WORKERS={env:WORKERS:-n2} nocext: DISABLE_SQLALCHEMY_CEXT=1 cov: COVERAGE={[testenv]cov_args} - sqlite: SQLITE=--db sqlite - postgresql: POSTGRESQL=--db postgresql - mysql: MYSQL=--db mysql --db pymysql - oracle: ORACLE=--db oracle --write-idents oracle_idents.txt --exclude-tag memory-intensive - mssql: MSSQL=--db pyodbc --db pymssql + sqlite: SQLITE={env:SQLITE:--db sqlite} + postgresql: POSTGRESQL={env:POSTGRESQL:--db postgresql} + mysql: MYSQL={env:MYSQL:--db mysql --db pymysql} + oracle: ORACLE={env:ORACLE:--db oracle} --write-idents oracle_idents.txt --exclude-tag memory-intensive + mssql: MSSQL={env:MSSQL:--db pyodbc --db pymssql} backendonly: BACKENDONLY=--backend-only # tox as of 2.0 blocks all environment variables from the # outside, unless they are here (or in TOX_TESTENV_PASSENV, # wildcards OK). Need at least these -passenv=ORACLE_HOME NLS_LANG +passenv=ORACLE_HOME NLS_LANG POSTGRESQL MYSQL ORACLE MSSQL SQLITE WORKERS # for nocext, we rm *.so in lib in case we are doing usedevelop=True commands= |