pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Style: Use type.__name__ in raises error messages for consistency

Open dariomesic opened this issue 1 month ago • 0 comments

Purpose

Addresses a FIXME in testing/python/raises_group.py that pointed out the inconsistent use of repr(type) vs type.__name__ in error messages.

This PR refactors the RaisesContext.__exit__ method in src/_pytest/raises.py to consistently use type.__name__ (e.g., 'ValueError') instead of repr(type) (e.g., <class 'ValueError'>) in all "DID NOT RAISE" error messages. This improves the readability and consistency of these assertion failures.

Tests

Because the library's error message format was changed, this PR also updates all the tests in testing/python/raises.py and testing/python/raises_group.py that were asserting the old, inconsistent message format.

dariomesic avatar Oct 29 '25 22:10 dariomesic