@@ -34,50 +34,38 @@ def test_argv_context_logging_isolation():
3434 allowing code under test to call logging.basicConfig() successfully even
3535 when test frameworks have already configured logging.
3636 """
37- # Setup: Create a mock handler to simulate pytest's handlers
3837 original_handlers = logging .root .handlers [:]
3938 mock_handler = logging .NullHandler ()
4039 logging .root .handlers .append (mock_handler )
4140
4241 try :
43- # Verify the mock handler is present
4442 assert mock_handler in logging .root .handlers , "Test setup failed"
4543
4644 with tempfile .TemporaryDirectory () as tmpdir :
4745 logfile = Path (tmpdir ) / "test.log"
4846
4947 with ArgvContext ("test_script.py" , str (logfile )):
50- # Inside context: handlers should be cleared
5148 handlers_before = logging .root .handlers [:]
5249 assert len (handlers_before ) == 0 , (
5350 "Handlers should be cleared inside ArgvContext"
5451 )
5552
56- # Configure logging (this should work now)
57- logging .basicConfig (
58- filename = str (logfile ),
59- level = logging .INFO ,
60- force = False , # Should work without force since handlers are cleared
61- )
53+ logging .basicConfig (filename = str (logfile ), level = logging .INFO )
6254
63- # Log a message
6455 logger = logging .getLogger (__name__ )
6556 logger .info ("Test message" )
6657
67- # After context: handlers should be restored
6858 assert mock_handler in logging .root .handlers , (
6959 "Original handlers should be restored after ArgvContext"
7060 )
7161
72- # Verify the log file was created and contains the message
7362 assert logfile .exists (), "Log file should have been created"
7463 log_content = logfile .read_text ()
7564 assert "Test message" in log_content , (
7665 "Log file should contain the test message"
7766 )
7867
7968 finally :
80- # Cleanup: Restore original handlers
8169 logging .root .handlers = original_handlers
8270
8371
0 commit comments