Pytest: str(err) on pytest.raises does not yield the exception message any more

Created on 30 Jun 2019  路  4Comments  路  Source: pytest-dev/pytest

Thanks for working on this beautiful project!

I use pytest extensively to test a project of mine, and I find that pytest-5.0.0, in combination with Python 3.8.0b1+, does not give the exception message any more if I apply str(err) to an exception err captured with pytest.raises.

A few days ago I was using pytest-4.6.3 with the same version of Python 3.8 dev and had no such issue.

A code like this one should be enough to reproduce the issue:

def test_error_str():
    with pytest.raises(Exception) as err:
        raise Exception("message")

    assert "message" in str(err)

The full details of what happens in the context of my project are available at https://github.com/mwouts/jupytext/issues/269.

Most helpful comment

Sure! I will update my tests to fix this. And many thanks for the quick response!

All 4 comments

you want str(err.value)

this was intentionally changed in 5.0.0, see the changelog: https://pytest.readthedocs.io/en/latest/changelog.html#removals

https://github.com/pytest-dev/pytest/issues/5412

Indeed!

It seems your question has been resolved so I'm closing this for now. Feel free to followup with further questions.

Sure! I will update my tests to fix this. And many thanks for the quick response!

btw, the reason you only hit this in python3.8 is it appears you're not actually installing pytest and just relying on travis's preinstalled version

Was this page helpful?
0 / 5 - 0 ratings