From: Federico Caselli Date: Tue, 31 Dec 2019 01:29:33 +0000 (-0500) Subject: Fix test failures under Windows X-Git-Tag: rel_1_3_13~17^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bead618047e29adf26ba34f92fdf0f8f05e101b8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix test failures under Windows Fixed a few test failures which would occur on Windows due to SQLite file locking issues, as well as some timing issues in connection pool related tests; pull request courtesy Federico Caselli. Note the pool related issues were fixed by Mike in I1a7162e67912d22c135fa517b687a073f8fd9151 but are being ticketed here. Fixes: #4946 Closes: #5055 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5055 Pull-request-sha: 36925573aff828bbdd725a4fed5394e06c775a98 Change-Id: Ic53ec82f5d588d0e26a2d033a17c6109900d7f63 (cherry picked from commit f461d710f9f848029603cf76f7c26725afdea11e) --- diff --git a/doc/build/changelog/unreleased_13/4946.rst b/doc/build/changelog/unreleased_13/4946.rst new file mode 100644 index 0000000000..f0946f4397 --- /dev/null +++ b/doc/build/changelog/unreleased_13/4946.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, tests + :tickets: 4946 + + Fixed a few test failures which would occur on Windows due to SQLite file + locking issues, as well as some timing issues in connection pool related + tests; pull request courtesy Federico Caselli. + diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 931631308c..01a0a54371 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -43,6 +43,7 @@ from sqlalchemy.testing import assert_raises from sqlalchemy.testing import assert_raises_message from sqlalchemy.testing import AssertsCompiledSQL from sqlalchemy.testing import AssertsExecutionResults +from sqlalchemy.testing import combinations from sqlalchemy.testing import engines from sqlalchemy.testing import eq_ from sqlalchemy.testing import expect_warnings @@ -711,40 +712,43 @@ class DialectTest(fixtures.TestBase, AssertsExecutionResults): e = create_engine("sqlite+pysqlite:///foo.db") assert e.pool.__class__ is pool.NullPool - def test_connect_args(self): + @combinations( + ( + "sqlite:///foo.db", # file path is absolute + ([os.path.abspath("foo.db")], {}), + ), + ( + "sqlite:////abs/path/to/foo.db", + ([os.path.abspath("/abs/path/to/foo.db")], {}), + ), + ("sqlite://", ([":memory:"], {})), + ( + "sqlite:///?check_same_thread=true", + ([":memory:"], {"check_same_thread": True}), + ), + ( + "sqlite:///file:path/to/database?" + "check_same_thread=true&timeout=10&mode=ro&nolock=1&uri=true", + ( + ["file:path/to/database?mode=ro&nolock=1"], + {"check_same_thread": True, "timeout": 10.0, "uri": True}, + ), + ), + ( + "sqlite:///file:path/to/database?" "mode=ro&uri=true", + (["file:path/to/database?mode=ro"], {"uri": True}), + ), + ( + "sqlite:///file:path/to/database?uri=true", + (["file:path/to/database"], {"uri": True}), + ), + ) + def test_connect_args(self, url, expected): """test create_connect_args scenarios including support for uri=True""" d = pysqlite_dialect.dialect() - for url, expected in [ - ( - "sqlite:///foo.db", # file path is absolute - ([os.path.abspath("foo.db")], {}), - ), - ("sqlite:////abs/path/to/foo.db", (["/abs/path/to/foo.db"], {})), - ("sqlite://", ([":memory:"], {})), - ( - "sqlite:///?check_same_thread=true", - ([":memory:"], {"check_same_thread": True}), - ), - ( - "sqlite:///file:path/to/database?" - "check_same_thread=true&timeout=10&mode=ro&nolock=1&uri=true", - ( - ["file:path/to/database?mode=ro&nolock=1"], - {"check_same_thread": True, "timeout": 10.0, "uri": True}, - ), - ), - ( - "sqlite:///file:path/to/database?" "mode=ro&uri=true", - (["file:path/to/database?mode=ro"], {"uri": True}), - ), - ( - "sqlite:///file:path/to/database?uri=true", - (["file:path/to/database"], {"uri": True}), - ), - ]: - url = make_url(url) - eq_(d.create_connect_args(url), expected) + url = make_url(url) + eq_(d.create_connect_args(url), expected) @testing.combinations( ("no_persisted", "ignore"), diff --git a/test/ext/test_horizontal_shard.py b/test/ext/test_horizontal_shard.py index affd7112c6..16694c86f5 100644 --- a/test/ext/test_horizontal_shard.py +++ b/test/ext/test_horizontal_shard.py @@ -29,6 +29,7 @@ from sqlalchemy.testing import eq_ from sqlalchemy.testing import fixtures from sqlalchemy.testing import provision from sqlalchemy.testing.engines import testing_engine +from sqlalchemy.testing.engines import testing_reaper # TODO: ShardTest can be turned into a base for further subclasses @@ -568,6 +569,8 @@ class LazyLoadIdentityKeyTest(fixtures.DeclarativeMappedTest): def teardown(self): for db in self.dbs: db.connect().invalidate() + + testing_reaper.close_all() for i in range(1, 3): os.remove("shard%d_%s.db" % (i, provision.FOLLOWER_IDENT))