1+ """
2+ ┌──────────────────────────────────────────────────────────────────────────────┐
3+ │ @author: Davidson Gomes │
4+ │ @file: conftest.py │
5+ │ Developed by: Davidson Gomes │
6+ │ Creation date: May 13, 2025 │
7+ 8+ ├──────────────────────────────────────────────────────────────────────────────┤
9+ │ @copyright © Evolution API 2025. All rights reserved. │
10+ │ Licensed under the Apache License, Version 2.0 │
11+ │ │
12+ │ You may not use this file except in compliance with the License. │
13+ │ You may obtain a copy of the License at │
14+ │ │
15+ │ http://www.apache.org/licenses/LICENSE-2.0 │
16+ │ │
17+ │ Unless required by applicable law or agreed to in writing, software │
18+ │ distributed under the License is distributed on an "AS IS" BASIS, │
19+ │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │
20+ │ See the License for the specific language governing permissions and │
21+ │ limitations under the License. │
22+ ├──────────────────────────────────────────────────────────────────────────────┤
23+ │ @important │
24+ │ For any future changes to the code in this file, it is recommended to │
25+ │ include, together with the modification, the information of the developer │
26+ │ who changed it and the date of modification. │
27+ └──────────────────────────────────────────────────────────────────────────────┘
28+ """
29+
130import pytest
231from fastapi .testclient import TestClient
332from sqlalchemy import create_engine
2251def db_session ():
2352 """Creates a fresh database session for each test."""
2453 Base .metadata .create_all (bind = engine ) # Create tables
25-
54+
2655 connection = engine .connect ()
2756 transaction = connection .begin ()
2857 session = TestingSessionLocal (bind = connection )
29-
58+
3059 # Use our test database instead of the standard one
3160 def override_get_db ():
3261 try :
3362 yield session
3463 session .commit ()
3564 finally :
3665 session .close ()
37-
66+
3867 app .dependency_overrides [get_db ] = override_get_db
39-
68+
4069 yield session # The test will run here
41-
70+
4271 # Teardown
4372 transaction .rollback ()
4473 connection .close ()
@@ -50,4 +79,4 @@ def override_get_db():
5079def client (db_session ):
5180 """Creates a FastAPI TestClient with database session fixture."""
5281 with TestClient (app ) as test_client :
53- yield test_client
82+ yield test_client
0 commit comments