Establish the session in class methods.
These are only called once, not before and after every test.communication
parent
dfb4236769
commit
0bc66ce4b9
|
@ -8,14 +8,16 @@ from setup import db_uri
|
|||
|
||||
|
||||
class DatabaseConnection(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.engine = create_engine(db_uri, echo=True)
|
||||
Session = sessionmaker(bind=self.engine)
|
||||
self.session = Session()
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
cls.engine = create_engine(db_uri, echo=True)
|
||||
Session = sessionmaker(bind=cls.engine)
|
||||
cls.session = Session()
|
||||
|
||||
def tearDown(self):
|
||||
self.engine.dispose()
|
||||
self.session.close()
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
cls.engine.dispose()
|
||||
cls.session.close()
|
||||
|
||||
def test_connection(self):
|
||||
with self.engine.connect() as connection:
|
||||
|
|
Loading…
Reference in New Issue