forked from LiveCarta/ContentGeneration
26 lines
781 B
Python
26 lines
781 B
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
import unittest
|
|
|
|
from src.logging_config import debug_log_lifecycle
|
|
|
|
|
|
class TestDebugLogLifecycle(unittest.TestCase):
|
|
def test_logs_function_start_and_end(self) -> None:
|
|
@debug_log_lifecycle
|
|
def sample(a: int, b: int) -> int:
|
|
return a + b
|
|
|
|
with self.assertLogs(sample.__module__, level="DEBUG") as captured:
|
|
result = sample(2, 3)
|
|
|
|
self.assertEqual(result, 5)
|
|
joined = "\n".join(captured.output)
|
|
self.assertIn("Start TestDebugLogLifecycle.test_logs_function_start_and_end.<locals>.sample", joined)
|
|
self.assertIn("End TestDebugLogLifecycle.test_logs_function_start_and_end.<locals>.sample", joined)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|