Skip to content

Commit

Permalink
Put test extension creation in setUpClass, not setUp (#557)
Browse files Browse the repository at this point in the history
setUp runs per test, which makes things extremely slow.
  • Loading branch information
msullivan authored Dec 11, 2024
1 parent 645fce0 commit 97e08e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
19 changes: 11 additions & 8 deletions tests/test_postgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# limitations under the License.
#

import unittest
from collections import namedtuple

from gel import _testbase as tb
Expand All @@ -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'''
Expand Down
21 changes: 12 additions & 9 deletions tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import array
import math
import unittest


# An array.array subtype where indexing doesn't work.
Expand All @@ -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('''
Expand Down

0 comments on commit 97e08e9

Please sign in to comment.