mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 02:47:59 +00:00
convert connect() into a context manager
This commit is contained in:
@@ -85,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
|
||||
|
||||
@@ -7,9 +7,8 @@ from nominatim.db.connection import connect
|
||||
|
||||
@pytest.fixture
|
||||
def db(temp_db):
|
||||
conn = connect('dbname=' + temp_db)
|
||||
yield conn
|
||||
conn.close()
|
||||
with connect('dbname=' + temp_db) as conn:
|
||||
yield conn
|
||||
|
||||
|
||||
def test_connection_table_exists(db, temp_db_cursor):
|
||||
|
||||
@@ -9,9 +9,8 @@ from nominatim.tools import admin
|
||||
|
||||
@pytest.fixture
|
||||
def db(temp_db, placex_table):
|
||||
conn = connect('dbname=' + temp_db)
|
||||
yield conn
|
||||
conn.close()
|
||||
with connect('dbname=' + temp_db) as conn:
|
||||
yield conn
|
||||
|
||||
def test_analyse_indexing_no_objects(db):
|
||||
with pytest.raises(UsageError):
|
||||
|
||||
@@ -10,6 +10,10 @@ def test_check_database_unknown_db(def_config, monkeypatch):
|
||||
assert 1 == chkdb.check_database(def_config)
|
||||
|
||||
|
||||
def test_check_database_fatal_test(def_config, temp_db):
|
||||
assert 1 == chkdb.check_database(def_config)
|
||||
|
||||
|
||||
def test_check_conection_good(temp_db_conn, def_config):
|
||||
assert chkdb.check_connection(temp_db_conn, def_config) == chkdb.CheckState.OK
|
||||
|
||||
|
||||
@@ -11,9 +11,8 @@ SQL_DIR = (Path(__file__) / '..' / '..' / '..' / 'lib-sql').resolve()
|
||||
|
||||
@pytest.fixture
|
||||
def db(temp_db):
|
||||
conn = connect('dbname=' + temp_db)
|
||||
yield conn
|
||||
conn.close()
|
||||
with connect('dbname=' + temp_db) as conn:
|
||||
yield conn
|
||||
|
||||
@pytest.fixture
|
||||
def db_with_tables(db):
|
||||
|
||||
Reference in New Issue
Block a user