From 0bebf34a82dc6dc6ec904645143582518fec1dcd Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Tue, 10 Dec 2024 17:13:43 -0800 Subject: [PATCH] Put test extension creation in setUpClass, not setUp setUp runs per test, which makes things extremely slow. --- tests/test_postgis.py | 19 +++++++++++-------- tests/test_vector.py | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/tests/test_postgis.py b/tests/test_postgis.py index 029ff57d..0a1f6ac4 100644 --- a/tests/test_postgis.py +++ b/tests/test_postgis.py @@ -16,6 +16,7 @@ # limitations under the License. # +import unittest from collections import namedtuple from gel import _testbase as tb @@ -34,27 +35,29 @@ class TestPostgis(tb.SyncQueryTestCase): Raw bytes used as sample GEOS data in (E)WKB format. ''' - def setUp(self): - super().setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() - if not self.client.query_required_single(''' + if not cls.client.query_required_single(''' select exists ( select sys::ExtensionPackage filter .name = 'postgis' ) '''): - self.skipTest("feature not implemented") + raise unittest.SkipTest("feature not implemented") - self.client.execute(''' + cls.client.execute(''' create extension postgis; ''') - def tearDown(self): + @classmethod + def tearDownClass(cls): try: - self.client.execute(''' + cls.client.execute(''' drop extension postgis; ''') finally: - super().tearDown() + super().tearDownClass() async def _test_postgis_geometry(self, wkt, wkb): val = self.client.query_single(f''' diff --git a/tests/test_vector.py b/tests/test_vector.py index b4708281..62b672d9 100644 --- a/tests/test_vector.py +++ b/tests/test_vector.py @@ -21,6 +21,7 @@ import array import math +import unittest # An array.array subtype where indexing doesn't work. @@ -35,29 +36,31 @@ class TestVector(tb.SyncQueryTestCase): PGVECTOR_VER = None - def setUp(self): - super().setUp() + @classmethod + def setUpClass(cls): + super().setUpClass() - self.PGVECTOR_VER = self.client.query_single(''' + cls.PGVECTOR_VER = cls.client.query_single(''' select assert_single(( select sys::ExtensionPackage filter .name = 'pgvector' )).version ''') - if self.PGVECTOR_VER is None: - self.skipTest("feature not implemented") + if cls.PGVECTOR_VER is None: + raise unittest.SkipTest("feature not implemented") - self.client.execute(''' + cls.client.execute(''' create extension pgvector; ''') - def tearDown(self): + @classmethod + def tearDownClass(cls): try: - self.client.execute(''' + cls.client.execute(''' drop extension pgvector; ''') finally: - super().tearDown() + super().tearDownClass() async def test_vector_01(self): val = self.client.query_single('''