X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/d81e152804b81f3d61ee743e436dd14fe924ee58..af7226393a45a0ea5b87967c3231392b0e12da64:/test/python/conftest.py diff --git a/test/python/conftest.py b/test/python/conftest.py index ecd40d7c..0e0e808c 100644 --- a/test/python/conftest.py +++ b/test/python/conftest.py @@ -36,6 +36,14 @@ class _TestingCursor(psycopg2.extras.DictCursor): return set((tuple(row) for row in self)) + def table_exists(self, table): + """ Check that a table with the given name exists in the database. + """ + num = self.scalar("""SELECT count(*) FROM pg_tables + WHERE tablename = %s""", (table, )) + return num == 1 + + @pytest.fixture def temp_db(monkeypatch): """ Create an empty database for the test. The database name is also @@ -77,9 +85,8 @@ def temp_db_with_extensions(temp_db): def temp_db_conn(temp_db): """ Connection to the test database. """ - conn = connection.connect('dbname=' + temp_db) - yield conn - conn.close() + with connection.connect('dbname=' + temp_db) as conn: + yield conn @pytest.fixture