Improve error message when pytest.warns fail #2150
The error message contains the expected type of warning and the
You could argue that having the stderr is good enough but in my original use case, either the stderr was very noisy or I managed to miss it completely. I reckon it does not hurt to have a clearer error message anyway.
The line of the error message is very long now. Let me know if you would rather have me split it manually or you have better ways to deal with it.
import warnings import pytest def test(): with pytest.warns(RuntimeWarning): warnings.warn('user', UserWarning) warnings.warn('import', ImportWarning)