sghorbal commited on
Commit
356f8cf
·
1 Parent(s): 788fb65

fix: handle transaction rollback warning

Browse files
Files changed (1) hide show
  1. tests/conftest.py +10 -6
tests/conftest.py CHANGED
@@ -14,6 +14,7 @@ from src.repository.common import get_session
14
 
15
  from src.entity import Base
16
 
 
17
  # Load all classes from src.entity
18
  module = importlib.import_module('src.entity')
19
 
@@ -62,16 +63,19 @@ def db_session(postgresql):
62
  Base.metadata.create_all(engine)
63
 
64
  connection = engine.connect()
65
- transaction = connection.begin()
66
 
67
  SessionLocal = sessionmaker(bind=connection)
68
  session = SessionLocal()
69
 
70
- yield session
71
-
72
- session.close()
73
- transaction.rollback()
74
- connection.close()
 
 
 
75
 
76
  # Use of fixture to inject a fake Redis client into the tests
77
  @pytest.fixture
 
14
 
15
  from src.entity import Base
16
 
17
+ # ----------------------------------------------------------------
18
  # Load all classes from src.entity
19
  module = importlib.import_module('src.entity')
20
 
 
63
  Base.metadata.create_all(engine)
64
 
65
  connection = engine.connect()
66
+ connection.begin()
67
 
68
  SessionLocal = sessionmaker(bind=connection)
69
  session = SessionLocal()
70
 
71
+ try:
72
+ yield session
73
+ except Exception:
74
+ session.rollback() # En cas d'exception, effectuer un rollback explicite
75
+ raise
76
+ finally:
77
+ session.close()
78
+ connection.close()
79
 
80
  # Use of fixture to inject a fake Redis client into the tests
81
  @pytest.fixture