Skip to content

Fix usage of message attr in Exception object#5

Merged
matux merged 1 commit intomasterfrom
matux/fix-exc-message
Sep 25, 2024
Merged

Fix usage of message attr in Exception object#5
matux merged 1 commit intomasterfrom
matux/fix-exc-message

Conversation

@matux
Copy link

@matux matux commented Sep 25, 2024

In Python 3, the message attribute has been removed from Exception and we're expected to obtain its string representation by invoking str on it, eg. str(exc).

In this case, since what's being captured is an AssertionError, message becomes a list where the second element contains the message passed to assert.

We can use args to access this which works on both Pythons.

I've also added tests triggering this assertion condition by passing an invalid sourcemap.


Tests ran in Python 2.7

pytest tests
============================ test session starts ============================
platform darwin -- Python 2.7.18, pytest-4.6.11, py-1.11.0, pluggy-0.13.1
rootdir: /Users/matux/code/rollbar/python-sourcemap
collected 17 items

tests/test_init.py ...                                                 [ 17%]
tests/test_integration.py ....                                         [ 41%]
tests/test_objects.py ..........                                       [100%]

============================ 17 passed in 0.12 seconds ======================

Tests ran in Python 3.10

pytest tests
============================ test session starts ============================
platform darwin -- Python 3.10.14, pytest-8.3.3, pluggy-1.5.0
rootdir: /Users/matux/code/rollbar/python-sourcemap
collected 17 items

tests/test_init.py ...                                                 [ 17%]
tests/test_integration.py ....                                         [ 41%]
tests/test_objects.py ..........                                       [100%]

============================ 17 passed in 0.07s =============================

@matux matux self-assigned this Sep 25, 2024
@matux matux merged commit bfca04f into master Sep 25, 2024
@matux matux deleted the matux/fix-exc-message branch September 25, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants