Skip to content

Commit f6028e6

Browse files
chore: add the version of python-gitlab to Exception
People will post tracebacks of AttributeError exceptions but not post information on the version of python-gitlab used. Add the version of python-gitlab to the AttributeError exception message.
1 parent a825844 commit f6028e6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

gitlab/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def __getattr__(self, name: str) -> Any:
129129
except KeyError as exc:
130130
message = (
131131
f"{type(self).__name__!r} object has no attribute {name!r}"
132+
f" (python-gitlab version: {gitlab.__version__})"
132133
)
133134
if self._created_from_list:
134135
message = (

tests/unit/test_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ def test_missing_attribute_does_not_raise_custom(self, fake_gitlab, fake_manager
103103
assert "was created via a list()" not in exc_str
104104
assert base._URL_ATTRIBUTE_ERROR not in exc_str
105105

106+
def test_missing_attribute_has_pg_version(self, fake_gitlab, fake_manager):
107+
"""Ensure a missing attribute raise our custom error message with the
108+
version of python-gitlab"""
109+
obj = FakeObject(manager=fake_manager, attrs={"foo": "bar"})
110+
with pytest.raises(AttributeError) as excinfo:
111+
obj.missing_attribute
112+
exc_str = str(excinfo.value)
113+
pg_version_str = f"(python-gitlab version: {gitlab.__version__})"
114+
assert pg_version_str in exc_str
115+
106116
def test_missing_attribute_from_list_raises_custom(self, fake_gitlab, fake_manager):
107117
"""Ensure a missing attribute raises our custom error message if the
108118
RESTObject was created from a list"""

0 commit comments

Comments
 (0)