Explorar o código

Fix Healthchecks tests that leak global state, breaking downstream tests (discovered in #543).

Dan Helfman %!s(int64=3) %!d(string=hai) anos
pai
achega
3561c93d74
Modificáronse 1 ficheiros con 12 adicións e 0 borrados
  1. 12 0
      tests/unit/hooks/test_healthchecks.py

+ 12 - 0
tests/unit/hooks/test_healthchecks.py

@@ -69,10 +69,18 @@ def test_format_buffered_logs_for_payload_without_handler_produces_empty_payload
     assert payload == ''
     assert payload == ''
 
 
 
 
+def mock_logger():
+    logger = flexmock()
+    logger.should_receive('addHandler')
+    logger.should_receive('removeHandler')
+    flexmock(module.logging).should_receive('getLogger').and_return(logger)
+
+
 def test_initialize_monitor_creates_log_handler_with_ping_body_limit():
 def test_initialize_monitor_creates_log_handler_with_ping_body_limit():
     ping_body_limit = 100
     ping_body_limit = 100
     monitoring_log_level = 1
     monitoring_log_level = 1
 
 
+    mock_logger()
     flexmock(module).should_receive('Forgetful_buffering_handler').with_args(
     flexmock(module).should_receive('Forgetful_buffering_handler').with_args(
         ping_body_limit - len(module.PAYLOAD_TRUNCATION_INDICATOR), monitoring_log_level
         ping_body_limit - len(module.PAYLOAD_TRUNCATION_INDICATOR), monitoring_log_level
     ).once()
     ).once()
@@ -85,6 +93,7 @@ def test_initialize_monitor_creates_log_handler_with_ping_body_limit():
 def test_initialize_monitor_creates_log_handler_with_default_ping_body_limit():
 def test_initialize_monitor_creates_log_handler_with_default_ping_body_limit():
     monitoring_log_level = 1
     monitoring_log_level = 1
 
 
+    mock_logger()
     flexmock(module).should_receive('Forgetful_buffering_handler').with_args(
     flexmock(module).should_receive('Forgetful_buffering_handler').with_args(
         module.DEFAULT_PING_BODY_LIMIT_BYTES - len(module.PAYLOAD_TRUNCATION_INDICATOR),
         module.DEFAULT_PING_BODY_LIMIT_BYTES - len(module.PAYLOAD_TRUNCATION_INDICATOR),
         monitoring_log_level,
         monitoring_log_level,
@@ -97,6 +106,7 @@ def test_initialize_monitor_creates_log_handler_with_zero_ping_body_limit():
     ping_body_limit = 0
     ping_body_limit = 0
     monitoring_log_level = 1
     monitoring_log_level = 1
 
 
+    mock_logger()
     flexmock(module).should_receive('Forgetful_buffering_handler').with_args(
     flexmock(module).should_receive('Forgetful_buffering_handler').with_args(
         ping_body_limit, monitoring_log_level
         ping_body_limit, monitoring_log_level
     ).once()
     ).once()
@@ -107,6 +117,7 @@ def test_initialize_monitor_creates_log_handler_with_zero_ping_body_limit():
 
 
 
 
 def test_initialize_monitor_creates_log_handler_when_send_logs_true():
 def test_initialize_monitor_creates_log_handler_when_send_logs_true():
+    mock_logger()
     flexmock(module).should_receive('Forgetful_buffering_handler').once()
     flexmock(module).should_receive('Forgetful_buffering_handler').once()
 
 
     module.initialize_monitor(
     module.initialize_monitor(
@@ -115,6 +126,7 @@ def test_initialize_monitor_creates_log_handler_when_send_logs_true():
 
 
 
 
 def test_initialize_monitor_bails_when_send_logs_false():
 def test_initialize_monitor_bails_when_send_logs_false():
+    mock_logger()
     flexmock(module).should_receive('Forgetful_buffering_handler').never()
     flexmock(module).should_receive('Forgetful_buffering_handler').never()
 
 
     module.initialize_monitor(
     module.initialize_monitor(