Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies = [
dev = [
"factory_boy<4",
"pytest-factoryboy<3",
"pytest",
"pytest<8.4",
"pytest-cov",
"sphinx-autobuild<=2024.5",
]
Expand Down
9 changes: 5 additions & 4 deletions snowexsql/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

def initialize(engine):
"""
Creates the original database from scratch, currently only for
point data

Creates the original database from scratch.
"""
meta = Base.metadata
meta.drop_all(bind=engine)
Expand Down Expand Up @@ -117,7 +115,10 @@ def db_session_with_credentials(credentials_path=None):
credentials_path (string): Full path to credentials file (Optional)

"""
yield get_db(credentials_path)
engine, session = get_db(credentials_path)
yield engine, session
session.close()
engine.dispose()


def get_table_attributes(DataCls):
Expand Down
10 changes: 8 additions & 2 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
load_credentials)
from sqlalchemy import Engine, MetaData
from sqlalchemy.orm import Session
from sqlalchemy import text


@pytest.fixture(scope='function')
Expand Down Expand Up @@ -75,8 +76,13 @@ def test_db_session_with_credentials(self, monkeypatch, test_db_info):
engine = test_engine
session = test_session

assert isinstance(engine, Engine)
assert isinstance(session, Session)
assert isinstance(engine, Engine)
assert isinstance(session, Session)
# Query to create a transaction
session.query(text('1')).all()

# On session.close(), all transactions should be gone
assert session._transaction is None

@pytest.mark.usefixtures('db_connection_string_patch')
@pytest.mark.parametrize("return_metadata, expected_objs", [
Expand Down