diff --git a/tests/test_transactions.py b/tests/test_transactions.py index 445df7470b56fcf4c332b6ed9218c36416fcb811..91157d33ae3dee9a98022536124c876ca5f6ced0 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -191,7 +191,7 @@ class TestTransactionLogging: assert last_log_message.funcName == "test_log_override_enter_exit_no_logger" assert last_log_message.filename == "test_transactions.py" - def test_specified_logger(self): + def test_specified_logger_is_used(self): logger = MagicMock() parameters = {} with transaction("name", parameters, logger=logger) as transaction_id: @@ -200,7 +200,7 @@ class TestTransactionLogging: assert logger.info.call_args_list[i].starts_with(message) assert logger.info.call_count == 4, f"Log calls incorrect {logger.info.call_args_list}" - def test_unspecified_logger(self): + def test_unspecified_logger_is_not_used(self): logger = MagicMock() parameters = {} with transaction("name", parameters) as transaction_id: diff --git a/tests/test_transactions_threaded.py b/tests/test_transactions_threaded.py index b6b35fb2b6ada06ba727318c281e2a541382c09a..9696139931e5dd4822715f50d0ad559c7a591775 100644 --- a/tests/test_transactions_threaded.py +++ b/tests/test_transactions_threaded.py @@ -18,34 +18,22 @@ class ThreadingLogsGenerator: self.pass_logger = pass_logger def thread_with_transaction_exception(self, thread_index): - if self.pass_logger: - try: - with transaction(f"Transaction thread [{thread_index}]", logger=self.logger): - self.logger.info( - f"Transaction thread in transaction [{thread_index}], in transaction" - ) - raise RuntimeError("An exception has occurred") - except RuntimeError: - pass - else: - try: - with transaction(f"Transaction thread [{thread_index}]"): - self.logger.info( - f"Transaction thread in transaction [{thread_index}], in transaction" - ) - raise RuntimeError("An exception has occurred") - except RuntimeError: - pass + logger = self.logger if self.pass_logger else None + try: + with transaction(f"Transaction thread [{thread_index}]", logger=logger): + self.logger.info( + f"Transaction thread in transaction [{thread_index}], in transaction" + ) + raise RuntimeError("An exception has occurred") + except RuntimeError: + pass def thread_with_transaction(self, thread_index): - if self.pass_logger: - with transaction(f"Transaction thread [{thread_index}]", logger=self.logger): - self.logger.info(f"Transaction thread [{thread_index}], in transaction") - self.logger.info(f"Thread log [{thread_index}], no transaction") - else: - with transaction(f"Transaction thread [{thread_index}]"): - self.logger.info(f"Transaction thread [{thread_index}], in transaction") - self.logger.info(f"Thread log [{thread_index}], no transaction") + logger = self.logger if self.pass_logger else None + with transaction(f"Transaction thread [{thread_index}]", logger=logger): + self.logger.info(f"Transaction thread [{thread_index}], in transaction") + self.logger.info(f"Thread log [{thread_index}], no transaction") + def thread_without_transaction(self, thread_index): self.logger.info(f"Thread log [{thread_index}], no transaction")