mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
* Add py::raise_from to enable chaining exceptions on Python 3.3+ * Use 'raise from' in initialization * Documenting the exact base version of _PyErr_FormatVFromCause, adding back `assert`s. Co-authored-by: Dustin Spicuzza <dustin@virtualroadside.com>
This commit is contained in:
committed by
GitHub
parent
6cbabc4b8c
commit
c8ce4b8df8
@@ -24,6 +24,22 @@ def test_error_already_set(msg):
|
||||
assert msg(excinfo.value) == "foo"
|
||||
|
||||
|
||||
@pytest.mark.skipif("env.PY2")
|
||||
def test_raise_from(msg):
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
m.raise_from()
|
||||
assert msg(excinfo.value) == "outer"
|
||||
assert msg(excinfo.value.__cause__) == "inner"
|
||||
|
||||
|
||||
@pytest.mark.skipif("env.PY2")
|
||||
def test_raise_from_already_set(msg):
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
m.raise_from_already_set()
|
||||
assert msg(excinfo.value) == "outer"
|
||||
assert msg(excinfo.value.__cause__) == "inner"
|
||||
|
||||
|
||||
def test_cross_module_exceptions(msg):
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
cm.raise_runtime_error()
|
||||
|
||||
Reference in New Issue
Block a user