This didn't work with python2.6, but since you are using pytest you can use with pytest.raises()  and it will work even in python3