🔧 fix(conftest.py): remove unused imports and commented out code
✨ feat(conftest.py): add session_getter fixture to create a blank session for testing 🔧 fix(test_custom_component.py): pass session_getter fixture to list_flows function for testing
This commit is contained in:
parent
2e7b35ddd5
commit
ddafdf31b5
2 changed files with 34 additions and 4 deletions
|
|
@ -1,3 +1,4 @@
|
|||
from contextlib import contextmanager
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import AsyncGenerator
|
||||
|
|
@ -116,3 +117,32 @@ def client_fixture(session: Session):
|
|||
|
||||
yield TestClient(app)
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
# @contextmanager
|
||||
# def session_getter():
|
||||
# try:
|
||||
# session = Session(engine)
|
||||
# yield session
|
||||
# except Exception as e:
|
||||
# print("Session rollback because of exception:", e)
|
||||
# session.rollback()
|
||||
# raise
|
||||
# finally:
|
||||
# session.close()
|
||||
|
||||
|
||||
# create a fixture for session_getter above
|
||||
@pytest.fixture(name="session_getter")
|
||||
def session_getter_fixture():
|
||||
engine = create_engine(
|
||||
"sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool
|
||||
)
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
@contextmanager
|
||||
def blank_session_getter():
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
|
||||
yield blank_session_getter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue