diff --git a/tests/test_validators.py b/tests/test_validators.py index 3bec62b03..2132a43ca 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -469,6 +469,19 @@ def test_fail(self): """ v = in_([1, 2, 3]) a = simple_attr("test") + with pytest.raises(ValueError) as e: + v(None, a, None) + assert ( + "'test' must be in [1, 2, 3] (got None)", + ) == e.value.args + + def test_fail_verbose(self): + """ + Raise verbose ValueError if the value is outside our options + and verbose_value_error is set to True. + """ + v = in_([1, 2, 3], verbose_value_error=True) + a = simple_attr("test") with pytest.raises(ValueError) as e: v(None, a, None) assert ( @@ -485,6 +498,20 @@ def test_fail_with_string(self): """ v = in_("abc") a = simple_attr("test") + with pytest.raises(ValueError) as e: + v(None, a, None) + assert ( + "'test' must be in 'abc' (got None)", + ) == e.value.args + + def test_fail_with_string_verbose(self): + """ + Raise verbose ValueError if the value is outside our options when + the options are specified as a string, verbose_value_error is set + to True and the value is not a string. + """ + v = in_("abc", verbose_value_error=True) + a = simple_attr("test") with pytest.raises(ValueError) as e: v(None, a, None) assert (