forked from 3wordchant/capsul-flask
getting unit tests to log properly
This commit is contained in:
parent
45d7e2c62e
commit
f5640a1d01
2
.gitignore
vendored
2
.gitignore
vendored
@ -17,4 +17,4 @@ build/
|
||||
*.egg-info/
|
||||
|
||||
.venv
|
||||
unittest-output.log
|
||||
unittest-log-output.log
|
@ -56,28 +56,38 @@ def authorized_as_hub(headers):
|
||||
def my_exec_info_message(exec_info):
|
||||
return "{}: {}".format(".".join([exec_info[0].__module__, exec_info[0].__name__]), exec_info[1])
|
||||
|
||||
|
||||
|
||||
mylog_current_test_id_container = {
|
||||
'value': '',
|
||||
}
|
||||
def set_mylog_test_id(test_id):
|
||||
mylog_current_test_id_container['value'] = ".".join(test_id.split(".")[-2:])
|
||||
|
||||
|
||||
def log_output_for_tests(app: Flask, message: str):
|
||||
if app.config['TESTING'] != False:
|
||||
if app.config['TESTING'] and mylog_current_test_id_container['value'] != "":
|
||||
file_object = open('unittest-log-output.log', 'a')
|
||||
file_object.write(message)
|
||||
file_object.write(f"{mylog_current_test_id_container['value']}: {message}\n")
|
||||
file_object.close()
|
||||
|
||||
|
||||
def mylog_debug(app: Flask, message: str):
|
||||
log_output_for_tests(app, f"DEBUG: {message}\n")
|
||||
log_output_for_tests(app, f"DEBUG: {message}")
|
||||
app.logger.debug(message)
|
||||
|
||||
def mylog_info(app: Flask, message: str):
|
||||
log_output_for_tests(app, f"INFO: {message}\n")
|
||||
log_output_for_tests(app, f"INFO: {message}")
|
||||
app.logger.info(message)
|
||||
|
||||
def mylog_warning(app: Flask, message: str):
|
||||
log_output_for_tests(app, f"WARNING: {message}\n")
|
||||
log_output_for_tests(app, f"WARNING: {message}")
|
||||
app.logger.warning(message)
|
||||
|
||||
def mylog_error(app: Flask, message: str):
|
||||
log_output_for_tests(app, f"ERROR: {message}\n")
|
||||
log_output_for_tests(app, f"ERROR: {message}")
|
||||
app.logger.error(message)
|
||||
|
||||
def mylog_critical(app: Flask, message: str):
|
||||
log_output_for_tests(app, f"CRITICAL: {message}\n")
|
||||
log_output_for_tests(app, f"CRITICAL: {message}")
|
||||
app.logger.critical(message)
|
@ -23,10 +23,10 @@ class BaseTestCase(TestCase):
|
||||
return self.app
|
||||
|
||||
def setUp(self):
|
||||
mylog_info(self.app, f"setting up {self.id()}")
|
||||
set_mylog_test_id(self.id())
|
||||
|
||||
def tearDown(self):
|
||||
mylog_info(self.app, f"tearing down {self.id()}")
|
||||
set_mylog_test_id("")
|
||||
|
||||
def _login(self, user_email):
|
||||
get_model().login(user_email)
|
||||
|
Loading…
Reference in New Issue
Block a user