pytest: No longer can extract message from exceptions in 5+ versions
I can’t extract the message of an exception using str(my_exception) when using pytest 5+. Here is an example :
E AssertionError: assert 'blabla' in '<ExceptionInfo Exception tblen=1>'
E + where '<ExceptionInfo Exception tblen=1>' = str(<ExceptionInfo Exception tblen=1>)
That test succeeds in previous versions (4.6.4 for instance)
I’ve been able to test it using the following example :
import pytest
def test_ex():
with pytest.raises(Exception) as e:
raise Exception('blabla')
assert 'blabla' in str(e)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (8 by maintainers)
Commits related to this issue
- integ tests: align to new ExceptionInfo str implementation related to https://github.com/pytest-dev/pytest/issues/5579 Signed-off-by: Francesco De Martino <fdm@amazon.com> — committed to demartinofra/aws-parallelcluster by demartinofra 5 years ago
- integ tests: align to new ExceptionInfo str implementation related to https://github.com/pytest-dev/pytest/issues/5579 Signed-off-by: Francesco De Martino <fdm@amazon.com> — committed to demartinofra/aws-parallelcluster by demartinofra 5 years ago
- integ tests: align to new ExceptionInfo str implementation related to https://github.com/pytest-dev/pytest/issues/5579 Signed-off-by: Francesco De Martino <fdm@amazon.com> — committed to demartinofra/aws-parallelcluster by demartinofra 5 years ago
- integ tests: align to new ExceptionInfo str implementation related to https://github.com/pytest-dev/pytest/issues/5579 Signed-off-by: Francesco De Martino <fdm@amazon.com> — committed to aws/aws-parallelcluster by demartinofra 5 years ago
- fix a new test failure due a change in how pytest represents exceptions See: https://github.com/pytest-dev/pytest/issues/5579 Signed-off-by: William Woodall <william@osrfoundation.org> — committed to ros2/launch by wjwwood 5 years ago
- Make ExceptionInfo.repr change more prominent Related to #5579 — committed to nicoddemus/pytest by nicoddemus 5 years ago
- fix a new test failure due a change in how pytest represents exceptions See: https://github.com/pytest-dev/pytest/issues/5579 Signed-off-by: William Woodall <william@osrfoundation.org> — committed to ros2/launch by wjwwood 5 years ago
- Revert "Revert "[execute_process] emulate_tty configurable and defaults to true"" (#277) * Revert "Revert "[execute_process] emulate_tty configurable and defaults to true (#265)" (#276)" This reve... — committed to ros2/launch by wjwwood 5 years ago
- Fix assert 'str' in str(ex) for pytest 5 See pytest-dev/pytest#5579 for change — committed to nismod/smif by tomalrussell 5 years ago
- Revert "Revert "[execute_process] emulate_tty configurable and defaults to true"" (#277) * Revert "Revert "[execute_process] emulate_tty configurable and defaults to true (#265)" (#276)" This reve... — committed to aws-ros-dev/launch by wjwwood 5 years ago
@nicoddemus I understand the change but it did smash a good bit of my test suite out of the blue when my CI suite pulled v5 instead of v4.X. I didn’t realize I was using undocumented behavior which in the end is on me but I suspect several others will get hit in the face by this as well.
Maybe adding an extra note somewhere that statements such as
assert "string" in str(err)
will no longer work would help with the pain. I read the CHANGELOG prior to finding this issue but I didn’t realize the impact of #5412 until seeing it detailed out here.Sorry, README was a typo, I meant CHANGELOG too.