|
5 | 5 | from decimal import Decimal
|
6 | 6 | import http.client
|
7 | 7 | import os
|
8 |
| -import sys |
9 | 8 | from functools import wraps
|
10 |
| -import logging |
11 | 9 | from unittest.mock import MagicMock, ANY
|
12 | 10 |
|
13 | 11 | import boto3
|
@@ -183,28 +181,25 @@ def lambda_test_function(event, context):
|
183 | 181 | assert Configuration.should_report == "123"
|
184 | 182 |
|
185 | 183 |
|
186 |
| -def test_wrapping_with_print_override(context): |
187 |
| - @lumigo_tracer(enhance_print=True) |
| 184 | +def test_wrapping_print_happy_flow(context): |
| 185 | + @lumigo_tracer() |
188 | 186 | def lambda_test_function(event, context):
|
189 |
| - print("hello\nworld") |
| 187 | + print("hello") |
190 | 188 | return 1
|
191 | 189 |
|
192 | 190 | with CaptureOutput() as capturer:
|
193 | 191 | assert lambda_test_function({}, context) == 1
|
194 |
| - assert Configuration.enhanced_print is True |
195 |
| - assert "RequestId: 1234 hello" in capturer.get_lines() |
196 |
| - assert "RequestId: 1234 world" in capturer.get_lines() |
| 192 | + assert any(line == "hello" for line in capturer.get_lines()) |
197 | 193 |
|
198 | 194 |
|
199 |
| -def test_wrapping_without_print_override(context): |
200 |
| - @lumigo_tracer() |
| 195 | +def test_wrapping_enhanced_print_backward_compatible(context): |
| 196 | + @lumigo_tracer(enhance_print=True) |
201 | 197 | def lambda_test_function(event, context):
|
202 | 198 | print("hello")
|
203 | 199 | return 1
|
204 | 200 |
|
205 | 201 | with CaptureOutput() as capturer:
|
206 | 202 | assert lambda_test_function({}, context) == 1
|
207 |
| - assert Configuration.enhanced_print is False |
208 | 203 | assert any(line == "hello" for line in capturer.get_lines())
|
209 | 204 |
|
210 | 205 |
|
@@ -273,78 +268,6 @@ def handler(event, context):
|
273 | 268 | assert SpansContainer._span
|
274 | 269 |
|
275 | 270 |
|
276 |
| -def test_wrapping_with_logging_override_default_usage(caplog, context): |
277 |
| - @lumigo_tracer(enhance_print=True) |
278 |
| - def lambda_test_function(event, context): |
279 |
| - logging.warning("hello\nworld") |
280 |
| - return 1 |
281 |
| - |
282 |
| - assert lambda_test_function({}, context) == 1 |
283 |
| - assert Configuration.enhanced_print is True |
284 |
| - assert any("RequestId: 1234" in line and "hello" in line for line in caplog.text.split("\n")) |
285 |
| - assert any("RequestId: 1234" in line and "world" in line for line in caplog.text.split("\n")) |
286 |
| - |
287 |
| - |
288 |
| -def test_wrapping_with_logging_exception(caplog, context): |
289 |
| - @lumigo_tracer(enhance_print=True) |
290 |
| - def lambda_test_function(event, context): |
291 |
| - logger = logging.getLogger("logger_name") |
292 |
| - handler = logging.StreamHandler() |
293 |
| - logger.addHandler(handler) |
294 |
| - |
295 |
| - try: |
296 |
| - 1 / 0 |
297 |
| - except Exception: # You must call the logging.exception method just inside the except part. |
298 |
| - logger.exception("hello") |
299 |
| - return 1 |
300 |
| - |
301 |
| - assert lambda_test_function({}, context) == 1 |
302 |
| - # Check all lines have exactly one RequestId. |
303 |
| - for line in caplog.text.splitlines(): |
304 |
| - assert line.startswith("RequestId: 1234") and line.count("RequestId: 1234") == 1 |
305 |
| - # Check the message was logged. |
306 |
| - test_message = [line for line in caplog.text.splitlines() if line.endswith("hello")][0].replace( |
307 |
| - " ", "" |
308 |
| - ) |
309 |
| - assert "ERROR" in test_message and "hello" in test_message |
310 |
| - |
311 |
| - |
312 |
| -def test_wrapping_with_logging_override_complex_usage(context): |
313 |
| - @lumigo_tracer(enhance_print=True) |
314 |
| - def lambda_test_function(event, context): |
315 |
| - handler = logging.StreamHandler(sys.stdout) |
316 |
| - formatter = logging.Formatter("%(name)s [%(levelname)s] %(message)s") # Format of a client. |
317 |
| - handler.setFormatter(formatter) |
318 |
| - logger = logging.getLogger("my_test") |
319 |
| - logger.handlers = [handler] |
320 |
| - logger.setLevel("INFO") |
321 |
| - |
322 |
| - logger.info("hello\nworld") |
323 |
| - return 1 |
324 |
| - |
325 |
| - with CaptureOutput() as capturer: |
326 |
| - assert lambda_test_function({}, context) == 1 |
327 |
| - assert Configuration.enhanced_print is True |
328 |
| - assert "RequestId: 1234 my_test [INFO] hello" in capturer.get_lines() |
329 |
| - assert "RequestId: 1234 world" in capturer.get_lines() |
330 |
| - |
331 |
| - |
332 |
| -def test_wrapping_without_logging_override(caplog, context): |
333 |
| - @lumigo_tracer() |
334 |
| - def lambda_test_function(event, context): |
335 |
| - logging.warning("hello\nworld") |
336 |
| - return 1 |
337 |
| - |
338 |
| - assert lambda_test_function({}, context) == 1 |
339 |
| - assert Configuration.enhanced_print is False |
340 |
| - assert any( |
341 |
| - "RequestId: 1234" not in line and "world" in line for line in caplog.text.split("\n") |
342 |
| - ) |
343 |
| - assert any( |
344 |
| - "RequestId: 1234" not in line and "hello" in line for line in caplog.text.split("\n") |
345 |
| - ) |
346 |
| - |
347 |
| - |
348 | 271 | @pytest.mark.parametrize(
|
349 | 272 | "event, expected_triggered_by, expected_message_id",
|
350 | 273 | [
|
|
0 commit comments