@@ -124,6 +124,41 @@ def test_init_with_repo_info_does_not_raise(self):
124124 assert metadata .project .id == "test-project-id"
125125 assert metadata .experiment .name == "test-exp"
126126
127+ def test_init_enable_atexit_flush (self ):
128+ from braintrust .logger import _HTTPBackgroundLogger
129+
130+ api_con_response = lambda : {
131+ "project" : {"id" : "test-project-id" , "name" : "test-project" },
132+ "experiment" : {"id" : "test-exp-id" , "name" : "test-exp" },
133+ }
134+
135+ with patch ("atexit.register" ) as mock_register :
136+ _HTTPBackgroundLogger (LazyValue (api_con_response , use_mutex = False )) # type: ignore
137+ mock_register .assert_called ()
138+
139+ def test_init_disable_atexit_flush (self ):
140+ from braintrust .logger import _HTTPBackgroundLogger
141+
142+ api_con_response = lambda : {
143+ "project" : {"id" : "test-project-id" , "name" : "test-project" },
144+ "experiment" : {"id" : "test-exp-id" , "name" : "test-exp" },
145+ }
146+
147+ with patch .dict (os .environ , {"BRAINTRUST_DISABLE_ATEXIT_FLUSH" : "True" }):
148+ with patch ("atexit.register" ) as mock_register :
149+ _HTTPBackgroundLogger (LazyValue (api_con_response , use_mutex = False )) # type: ignore
150+ mock_register .assert_not_called ()
151+
152+ with patch .dict (os .environ , {"BRAINTRUST_DISABLE_ATEXIT_FLUSH" : "1" }):
153+ with patch ("atexit.register" ) as mock_register :
154+ _HTTPBackgroundLogger (LazyValue (api_con_response , use_mutex = False )) # type: ignore
155+ mock_register .assert_not_called ()
156+
157+ with patch .dict (os .environ , {"BRAINTRUST_DISABLE_ATEXIT_FLUSH" : "yes" }):
158+ with patch ("atexit.register" ) as mock_register :
159+ _HTTPBackgroundLogger (LazyValue (api_con_response , use_mutex = False )) # type: ignore
160+ mock_register .assert_not_called ()
161+
127162
128163class TestLogger (TestCase ):
129164 def test_extract_attachments_no_op (self ):
0 commit comments