Skip to content

Commit

Permalink
redis fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MeninoNias committed Jul 29, 2024
1 parent 4ee9afb commit 89ee1ad
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -12,5 +12,5 @@ POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

#Redis
REDIS_HOST= redis
REDIS_HOST= localhost
REDIS_PORT= 6379
6 changes: 5 additions & 1 deletion task/main.py
Original file line number Diff line number Diff line change
@@ -31,8 +31,12 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
logging.info("Cache initialized successfully.")
except Exception as e:
logging.error(f"Error initializing cache: {e}")
yield

yield
finally:
# Clean up resources if needed
await redis.close()
logging.info("Redis connection closed.")


app = FastAPI(
10 changes: 8 additions & 2 deletions task/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -16,15 +16,21 @@ def session():
table_registry.metadata.create_all(engine)

with Session(engine) as session:
yield session
try:
yield session
finally:
session.close()

table_registry.metadata.drop_all(engine)


@pytest.fixture
def client(session):
def get_session_override():
return session
try:
yield session
finally:
session.close()

with TestClient(app) as client:
app.dependency_overrides[get_session] = get_session_override

0 comments on commit 89ee1ad

Please sign in to comment.