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):
|
class DatabaseConnection(unittest.TestCase):
|
||||||
def setUp(self):
|
@classmethod
|
||||||
self.engine = create_engine(db_uri, echo=True)
|
def setUpClass(cls) -> None:
|
||||||
Session = sessionmaker(bind=self.engine)
|
cls.engine = create_engine(db_uri, echo=True)
|
||||||
self.session = Session()
|
Session = sessionmaker(bind=cls.engine)
|
||||||
|
cls.session = Session()
|
||||||
|
|
||||||
def tearDown(self):
|
@classmethod
|
||||||
self.engine.dispose()
|
def tearDownClass(cls) -> None:
|
||||||
self.session.close()
|
cls.engine.dispose()
|
||||||
|
cls.session.close()
|
||||||
|
|
||||||
def test_connection(self):
|
def test_connection(self):
|
||||||
with self.engine.connect() as connection:
|
with self.engine.connect() as connection:
|
||||||
|
|
Loading…
Reference in New Issue