mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Python 3.11+: Add __notes__ to error_already_set::what() output. (#4678)
* First version adding `__notes__` to `error_already_set::what()` output.
* Fix trivial oversight (missing adjustment in existing test).
* Minor enhancements of new code.
* Re-enable `cmake --target cpptest -j 2`
* Revert "Re-enable `cmake --target cpptest -j 2`"
This reverts commit 60816285e9.
* Add general comment explaining why the `error_fetch_and_normalize` code is so unusual.
This commit is contained in:
committed by
GitHub
parent
19816f0db7
commit
ce9bbc0a21
@@ -317,13 +317,7 @@ def test_error_already_set_what_with_happy_exceptions(
|
||||
assert what == expected_what
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
# Intentionally very specific:
|
||||
"sys.version_info == (3, 12, 0, 'alpha', 7)",
|
||||
reason="WIP: https://github.com/python/cpython/issues/102594",
|
||||
)
|
||||
@pytest.mark.skipif("env.PYPY", reason="PyErr_NormalizeException Segmentation fault")
|
||||
def test_flaky_exception_failure_point_init():
|
||||
def _test_flaky_exception_failure_point_init_before_py_3_12():
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
m.error_already_set_what(FlakyException, ("failure_point_init",))
|
||||
lines = str(excinfo.value).splitlines()
|
||||
@@ -337,7 +331,33 @@ def test_flaky_exception_failure_point_init():
|
||||
# Checking the first two lines of the traceback as formatted in error_string():
|
||||
assert "test_exceptions.py(" in lines[3]
|
||||
assert lines[3].endswith("): __init__")
|
||||
assert lines[4].endswith("): test_flaky_exception_failure_point_init")
|
||||
assert lines[4].endswith(
|
||||
"): _test_flaky_exception_failure_point_init_before_py_3_12"
|
||||
)
|
||||
|
||||
|
||||
def _test_flaky_exception_failure_point_init_py_3_12():
|
||||
# Behavior change in Python 3.12: https://github.com/python/cpython/issues/102594
|
||||
what, py_err_set_after_what = m.error_already_set_what(
|
||||
FlakyException, ("failure_point_init",)
|
||||
)
|
||||
assert not py_err_set_after_what
|
||||
lines = what.splitlines()
|
||||
assert lines[0].endswith("ValueError[WITH __notes__]: triggered_failure_point_init")
|
||||
assert lines[1] == "__notes__ (len=1):"
|
||||
assert "Normalization failed:" in lines[2]
|
||||
assert "FlakyException" in lines[2]
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
"env.PYPY and sys.version_info[:2] < (3, 12)",
|
||||
reason="PyErr_NormalizeException Segmentation fault",
|
||||
)
|
||||
def test_flaky_exception_failure_point_init():
|
||||
if sys.version_info[:2] < (3, 12):
|
||||
_test_flaky_exception_failure_point_init_before_py_3_12()
|
||||
else:
|
||||
_test_flaky_exception_failure_point_init_py_3_12()
|
||||
|
||||
|
||||
def test_flaky_exception_failure_point_str():
|
||||
|
||||
Reference in New Issue
Block a user