Establish the session in class methods.

These are only called once, not before and after every test.
communication
junos 2021-02-02 15:44:53 +01:00
parent dfb4236769
commit 0bc66ce4b9
1 changed files with 9 additions and 7 deletions

View File

@ -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: