From: Mike Bayer Date: Thu, 20 Jun 2019 21:18:59 +0000 (-0400) Subject: Add option for "sparse" backend tests and apply to memusage X-Git-Tag: rel_1_3_6~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8df8a1b37ca42a3f564652354f68a2887c0fbc8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add option for "sparse" backend tests and apply to memusage The memusage tests are extremely time and memory intensive, and when CI runs against MySQL or Postgresql there are many database/driver combinations for which the "backend" tests repeatedly run; as these tests are more oriented towards basic dialect interaction, add a new "sparse" backend option that will run the tests only once per base dialect. Change-Id: I312aa0332d7ec1ff4e2faa15f6b189d6f0f68393 (cherry picked from commit 0ad64da3971bd4ac42699cf891fd689e7291cd2f) --- diff --git a/lib/sqlalchemy/testing/plugin/plugin_base.py b/lib/sqlalchemy/testing/plugin/plugin_base.py index ef44a5906b..8f79b41631 100644 --- a/lib/sqlalchemy/testing/plugin/plugin_base.py +++ b/lib/sqlalchemy/testing/plugin/plugin_base.py @@ -93,7 +93,7 @@ def setup_options(make_option): "--backend-only", action="store_true", dest="backend_only", - help="Run only tests marked with __backend__", + help="Run only tests marked with __backend__ or __sparse_backend__", ) make_option( "--nomemory", @@ -483,8 +483,10 @@ def want_class(cls): return False elif cls.__name__.startswith("_"): return False - elif config.options.backend_only and not getattr( - cls, "__backend__", False + elif ( + config.options.backend_only + and not getattr(cls, "__backend__", False) + and not getattr(cls, "__sparse_backend__", False) ): return False else: @@ -519,8 +521,11 @@ def want_method(cls, fn): def generate_sub_tests(cls, module): - if getattr(cls, "__backend__", False): - for cfg in _possible_configs_for_cls(cls): + if getattr(cls, "__backend__", False) or getattr( + cls, "__sparse_backend__", False + ): + sparse = getattr(cls, "__sparse_backend__", False) + for cfg in _possible_configs_for_cls(cls, sparse=sparse): orig_name = cls.__name__ # we can have special chars in these names except for the @@ -589,7 +594,7 @@ def after_test(test): engines.testing_reaper._after_test_ctx() -def _possible_configs_for_cls(cls, reasons=None): +def _possible_configs_for_cls(cls, reasons=None, sparse=False): all_configs = set(config.Config.all_configs()) if cls.__unsupported_on__: @@ -632,6 +637,25 @@ def _possible_configs_for_cls(cls, reasons=None): if all_configs.difference(non_preferred): all_configs.difference_update(non_preferred) + if sparse: + # pick only one config from each base dialect + # sorted so we get the same backend each time selecting the highest + # server version info. + per_dialect = {} + for cfg in reversed( + sorted( + all_configs, + key=lambda cfg: ( + cfg.db.name, + cfg.db.dialect.server_version_info, + ), + ) + ): + db = cfg.db.name + if db not in per_dialect: + per_dialect[db] = cfg + return per_dialect.values() + return all_configs diff --git a/test/aaa_profiling/test_memusage.py b/test/aaa_profiling/test_memusage.py index 8e7bd57bb4..d1e9387ff4 100644 --- a/test/aaa_profiling/test_memusage.py +++ b/test/aaa_profiling/test_memusage.py @@ -264,7 +264,7 @@ class MemUsageWBackendTest(EnsureZeroed): __tags__ = ("memory_intensive",) __requires__ = "cpython", "memory_process_intensive" - __backend__ = True + __sparse_backend__ = True # ensure a pure growing test trips the assertion @testing.fails_if(lambda: True)