From 0bc66ce4b962986421a8a457ec10bd7aebc4c410 Mon Sep 17 00:00:00 2001 From: junos Date: Tue, 2 Feb 2021 15:44:53 +0100 Subject: [PATCH] Establish the session in class methods. These are only called once, not before and after every test. --- test/test_database.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/test_database.py b/test/test_database.py index 992dea5..c9f6085 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -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: