8
8
9
9
import pytest
10
10
11
- from mcpcat .modules .logging import write_to_log , debug_mode
11
+ from mcpcat .modules .logging import write_to_log , set_debug_mode
12
12
13
13
14
14
class TestLogging :
@@ -31,14 +31,8 @@ def cleanup_log_file(self):
31
31
32
32
def test_write_to_log_creates_file (self , tmp_path ):
33
33
"""Test that write_to_log creates the log file if it doesn't exist."""
34
- # Enable debug mode using environment variable MCPCAT_DEBUG_MODE
35
- os .environ ["MCPCAT_DEBUG_MODE" ] = "true"
36
- global debug_mode
37
- debug_mode = (
38
- os .getenv ("MCPCAT_DEBUG_MODE" ).lower ()
39
- if os .getenv ("MCPCAT_DEBUG_MODE" ) != None
40
- else str (debug_mode ).lower ()
41
- )
34
+ # Enable debug mode
35
+ set_debug_mode (True )
42
36
43
37
# Use a unique file name for this test
44
38
unique_id = str (uuid .uuid4 ())
@@ -66,17 +60,8 @@ def test_write_to_log_creates_file(self, tmp_path):
66
60
67
61
def test_write_to_log_checks_debug_mode (self , tmp_path ):
68
62
"""Test that write_to_log writes to file when debug mode is enabled."""
69
- # Check that MCPCAT_DEBUG_MODE overrides the default setting and writes log to file
70
- os .environ ["MCPCAT_DEBUG_MODE" ] = "true"
71
- global debug_mode
72
- debug_mode = (
73
- os .getenv ("MCPCAT_DEBUG_MODE" ).lower ()
74
- if os .getenv ("MCPCAT_DEBUG_MODE" ) != None
75
- else str (debug_mode ).lower ()
76
- )
77
- assert debug_mode == "true" , (
78
- "Environment variable failed to override default setting"
79
- )
63
+ # Enable debug mode
64
+ set_debug_mode (True )
80
65
81
66
# Use a unique file name for this test
82
67
unique_id = str (uuid .uuid4 ())
@@ -103,12 +88,7 @@ def test_write_to_log_checks_debug_mode(self, tmp_path):
103
88
assert "T" in content , "Timestamp not in ISO format"
104
89
105
90
# Check that log file is not created when debug mode is disabled
106
- os .environ ["MCPCAT_DEBUG_MODE" ] = "false"
107
- debug_mode = (
108
- os .getenv ("MCPCAT_DEBUG_MODE" ).lower ()
109
- if os .getenv ("MCPCAT_DEBUG_MODE" ) != None
110
- else str (debug_mode ).lower ()
111
- )
91
+ set_debug_mode (False )
112
92
113
93
# Use a unique file name for this test
114
94
unique_id = str (uuid .uuid4 ())
@@ -127,14 +107,8 @@ def test_write_to_log_checks_debug_mode(self, tmp_path):
127
107
128
108
def test_write_to_log_appends_messages (self , tmp_path ):
129
109
"""Test that write_to_log appends to existing log file."""
130
- # Enable debug mode using environment variable MCPCAT_DEBUG_MODE
131
- os .environ ["MCPCAT_DEBUG_MODE" ] = "true"
132
- global debug_mode
133
- debug_mode = (
134
- os .getenv ("MCPCAT_DEBUG_MODE" ).lower ()
135
- if os .getenv ("MCPCAT_DEBUG_MODE" ) != None
136
- else str (debug_mode ).lower ()
137
- )
110
+ # Enable debug mode
111
+ set_debug_mode (True )
138
112
139
113
# Use a unique file name for this test
140
114
unique_id = str (uuid .uuid4 ())
@@ -184,14 +158,8 @@ def test_write_to_log_appends_messages(self, tmp_path):
184
158
185
159
def test_write_to_log_handles_directory_creation (self , tmp_path ):
186
160
"""Test that write_to_log creates parent directories if needed."""
187
- # Enable debug mode using environment variable MCPCAT_DEBUG_MODE
188
- os .environ ["MCPCAT_DEBUG_MODE" ] = "true"
189
- global debug_mode
190
- debug_mode = (
191
- os .getenv ("MCPCAT_DEBUG_MODE" ).lower ()
192
- if os .getenv ("MCPCAT_DEBUG_MODE" ) != None
193
- else str (debug_mode ).lower ()
194
- )
161
+ # Enable debug mode
162
+ set_debug_mode (True )
195
163
196
164
# Use a unique file name for this test
197
165
unique_id = str (uuid .uuid4 ())
@@ -211,14 +179,8 @@ def test_write_to_log_handles_directory_creation(self, tmp_path):
211
179
212
180
def test_write_to_log_silently_handles_errors (self , tmp_path , monkeypatch ):
213
181
"""Test that write_to_log doesn't raise exceptions on errors."""
214
- # Enable debug mode using environment variable MCPCAT_DEBUG_MODE
215
- os .environ ["MCPCAT_DEBUG_MODE" ] = "true"
216
- global debug_mode
217
- debug_mode = (
218
- os .getenv ("MCPCAT_DEBUG_MODE" ).lower ()
219
- if os .getenv ("MCPCAT_DEBUG_MODE" ) != None
220
- else str (debug_mode ).lower ()
221
- )
182
+ # Enable debug mode
183
+ set_debug_mode (True )
222
184
223
185
# Use a unique file name for this test
224
186
unique_id = str (uuid .uuid4 ())
@@ -243,6 +205,9 @@ def test_write_to_log_silently_handles_errors(self, tmp_path, monkeypatch):
243
205
244
206
def test_log_format (self , tmp_path ):
245
207
"""Test the format of log entries."""
208
+ # Enable debug mode
209
+ set_debug_mode (True )
210
+
246
211
# Use a unique file name for this test
247
212
unique_id = str (uuid .uuid4 ())
248
213
log_file = tmp_path / f"test_mcpcat_{ unique_id } .log"
0 commit comments