예제 #1
0
def test_reraise_without_value():
    with pytest.raises(ValidationError) as caught:
        exceptions.raise_from(ValidationError, None)

    # The first is obvious from pytest.raises. The rest tests
    # known attributes
    assert caught.type == ValidationError
    assert str(caught.value) == ''
예제 #2
0
def test_reraise_with_value():
    with pytest.raises(ValidationError) as caught:
        try:
            raise RuntimeError("foo")
        except RuntimeError as inner:
            exceptions.raise_from(ValidationError, inner)

    # The first is obvious from pytest.raises. The rest tests
    # known attributes
    assert caught.type == ValidationError
    assert str(caught.value) == 'foo'
예제 #3
0
def test_reraise_with_empty_value_string_extra_message():
    with pytest.raises(ValidationError) as caught:
        try:
            raise RuntimeError()
        except RuntimeError as inner:
            exceptions.raise_from(ValidationError, inner, "asdf")

    # The first is obvious from pytest.raises. The rest tests
    # known attributes
    assert caught.type == ValidationError
    assert str(caught.value) == "asdf"