From 404e69426b05a82d905cbb3ad33adafccddb00dd Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 5 Jan 2019 22:42:08 -0500 Subject: Assorted pre-Black fixes Fixes to the test suite, a few errant imports, and setup.py: - mysql and postgresql have unused 'json' imports; remove - postgresql is exporting the 'json' symbol, remove - make sure setup.py can find __version__ using " or ' - retry logic in provision create database for postgresql fixed - refactor test_magazine to use cls.tables rather than globals - remove unused class in test_scoping - add a comment to test_deprecations that this test suite itself is deprecated - don't use mapper() and orm_mapper() in test_unitofwork, just use mapper() - remove dupe test_scalar_set_None test in test_attributes - Python 2.7 and above includes unittest.SkipTest, remove pre-2.7 fallback - use imported SkipTest in profiling - declarative test_reflection tests with "reflectable_autoincrement" already don't run on oracle or firebird; remove conditional logic for these, which also removes an "id" symbol - clean up test in test_functions, remove print statement - remove dupe test_literal_processor_coercion_native_int_out_of_range in test/sql/test_types.py - fix psycopg2_hstore ref Change-Id: I7b3444f8546aac82be81cd1e7b6d8b2ad6834fe6 --- lib/sqlalchemy/testing/config.py | 6 +----- lib/sqlalchemy/testing/profiling.py | 2 +- lib/sqlalchemy/testing/provision.py | 9 ++++++--- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'lib/sqlalchemy/testing') diff --git a/lib/sqlalchemy/testing/config.py b/lib/sqlalchemy/testing/config.py index dfe0da94b..e9cfb3de9 100644 --- a/lib/sqlalchemy/testing/config.py +++ b/lib/sqlalchemy/testing/config.py @@ -6,6 +6,7 @@ # the MIT License: http://www.opensource.org/licenses/mit-license.php import collections +from unittest import SkipTest as _skip_test_exception requirements = None db = None @@ -16,11 +17,6 @@ test_schema = None test_schema_2 = None _current = None -try: - from unittest import SkipTest as _skip_test_exception -except ImportError: - _skip_test_exception = None - class Config(object): def __init__(self, db, db_opts, options, file_config): diff --git a/lib/sqlalchemy/testing/profiling.py b/lib/sqlalchemy/testing/profiling.py index 42265f7cb..fab99b186 100644 --- a/lib/sqlalchemy/testing/profiling.py +++ b/lib/sqlalchemy/testing/profiling.py @@ -206,7 +206,7 @@ def function_call_count(variance=0.05): @contextlib.contextmanager def count_functions(variance=0.05): if cProfile is None: - raise SkipTest("cProfile is not installed") + raise config._skip_test_exception("cProfile is not installed") if not _profile_stats.has_stats() and not _profile_stats.write: config.skip_test( diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py index 4c749d382..c0ca7c1cb 100644 --- a/lib/sqlalchemy/testing/provision.py +++ b/lib/sqlalchemy/testing/provision.py @@ -170,11 +170,16 @@ def _pg_create_db(cfg, eng, ident): pass if not template_db: template_db = conn.scalar("select current_database()") - for attempt in range(3): + + attempt = 0 + while True: try: conn.execute( "CREATE DATABASE %s TEMPLATE %s" % (ident, template_db)) except exc.OperationalError as err: + attempt += 1 + if attempt >= 3: + raise if "accessed by other users" in str(err): log.info( "Waiting to create %s, URI %r, " @@ -183,8 +188,6 @@ def _pg_create_db(cfg, eng, ident): time.sleep(.5) else: break - else: - raise err @_create_db.for_db("mysql") -- cgit v1.2.1