Skip to content

Commit 529f1fa

Browse files
JohnVillalovosnejch
authored andcommitted
fix: user.warn() to show correct filename of issue
Previously would only go to the 2nd level of the stack for determining the offending filename and line number. When it should be showing the first filename outside of the python-gitlab source code. As we want it to show the warning for the user of the libraries code. Update test to show it works as expected.
1 parent e11d889 commit 529f1fa

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

gitlab/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ def warn(
191191
stacklevel = 1
192192
warning_from = ""
193193
for stacklevel, frame in enumerate(reversed(stack), start=1):
194-
if stacklevel == 2:
195-
warning_from = f" (python-gitlab: {frame.filename}:{frame.lineno})"
194+
warning_from = f" (python-gitlab: {frame.filename}:{frame.lineno})"
196195
frame_dir = str(pathlib.Path(frame.filename).parent.resolve())
197196
if not frame_dir.startswith(str(pg_dir)):
198197
break

tests/functional/api/test_gitlab.py

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def test_list_default_warning(gl):
252252
assert len(record) == 1
253253
warning = record[0]
254254
assert __file__ == warning.filename
255+
assert __file__ in str(warning.message)
255256

256257

257258
def test_list_page_nowarning(gl, recwarn):

tests/unit/test_gitlab_http_methods.py

+1
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ def test_list_request_pagination_warning(gl):
600600
message = str(warning.message)
601601
assert "Calling a `list()` method" in message
602602
assert "python-gitlab.readthedocs.io" in message
603+
assert __file__ in message
603604
assert __file__ == warning.filename
604605
assert isinstance(result, list)
605606
assert len(result) == 20

0 commit comments

Comments
 (0)