Skip to content

Commit b1340fb

Browse files
committed
test(loguru): Remove hardcoded line number in test_just_log
Use inspect to dynamically compute the correct line number instead of hard coding it. Fixes GH-4454
1 parent 9e1cedd commit b1340fb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/integrations/loguru/test_loguru.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest.mock import MagicMock, patch
2+
import inspect
23

34
import pytest
45
from loguru import logger
@@ -54,12 +55,17 @@ def test_just_log(
5455
)
5556
events = capture_events()
5657

58+
frame = inspect.currentframe()
59+
assert frame is not None
60+
log_line_number = frame.f_lineno + 1
5761
getattr(logger, level.name.lower())("test")
5862

5963
formatted_message = (
6064
" | "
6165
+ "{:9}".format(level.name.upper())
62-
+ "| tests.integrations.loguru.test_loguru:test_just_log:57 - test"
66+
+ "| tests.integrations.loguru.test_loguru:test_just_log:{} - test".format(
67+
log_line_number
68+
)
6369
)
6470

6571
if not created_event:

0 commit comments

Comments
 (0)