Skip to content
Snippets Groups Projects
Commit 2c3e7c38 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-828: class variable instantation and checkig for None, so we can handle any...

SW-828: class variable instantation and checkig for None, so we can handle any exception during setup phase.
parent 9c4d3ee8
No related branches found
No related tags found
2 merge requests!74Lofar release 4 0,!72Resolve SW-828
......@@ -34,6 +34,11 @@ class PostgresTestMixin():
It implements the unittest setUpClass/tearDownClass methods and uses them as a template method pattern to do all the testing-database setup/teardown work for you.
'''
# class variables are initialized in setUpClass
_postgresql = None
dbcreds = None
db = None
@classmethod
def setUpClass(cls):
logger.info('setting up test-database instance...')
......@@ -80,9 +85,10 @@ class PostgresTestMixin():
cls.print_database_instance_log()
try:
logger.info('removing test-database instance at %s', cls.dbcreds.stringWithHiddenPassword())
cls._postgresql.stop()
logger.info('test-database instance removed')
if cls._postgresql:
logger.info('removing test-database instance at %s', cls.dbcreds.stringWithHiddenPassword())
cls._postgresql.stop()
logger.info('test-database instance removed')
except Exception as e:
logger.info('error while removing test-database instance at %s: %s', cls.dbcreds.stringWithHiddenPassword(), e)
......@@ -105,8 +111,9 @@ class PostgresTestMixin():
def close_database_connection(cls):
''' close the database connection created in create_database_connection'''
try:
logger.info('Closing PostgresDatabaseConnection to test-database %s...', cls.db)
cls.db.disconnect()
if cls.db:
logger.info('Closing PostgresDatabaseConnection to test-database %s...', cls.db)
cls.db.disconnect()
except Exception as e:
logger.error("Error while closing PostgresDatabaseConnection to test-database: %s", e)
......@@ -114,10 +121,11 @@ class PostgresTestMixin():
def print_database_instance_log(cls):
'''print the log of the testing-database instance (can help debugging sql statements)'''
try:
db_log_file_name = os.path.join(cls._postgresql.base_dir, '%s.log' % cls._postgresql.name)
logger.info('Printing test-postgress-database server log for reference: %s', db_log_file_name)
with open(db_log_file_name, 'r') as db_log_file:
for line in db_log_file.readlines():
print(" postgres log: %s" % line.strip(), file=sys.stderr)
if cls._postgresql:
db_log_file_name = os.path.join(cls._postgresql.base_dir, '%s.log' % cls._postgresql.name)
logger.info('Printing test-postgress-database server log for reference: %s', db_log_file_name)
with open(db_log_file_name, 'r') as db_log_file:
for line in db_log_file.readlines():
print(" postgres log: %s" % line.strip(), file=sys.stderr)
except Exception as e:
logger.error("Error while printing test-postgress-database server log: %s", e)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment