1919from cattr import GenConverter as Converter
2020from cattr import UnstructureStrategy
2121from cattr ._compat import is_py39_plus , is_py310_plus
22+ from cattr .errors import ForbiddenExtraKeyError
2223from cattr .gen import make_dict_structure_fn , override
2324
2425from . import (
@@ -85,7 +86,7 @@ def test_forbid_extra_keys(cls_and_vals):
8586 while bad_key in unstructured :
8687 bad_key += "A"
8788 unstructured [bad_key ] = 1
88- with pytest .raises (Exception ):
89+ with pytest .raises (ForbiddenExtraKeyError ):
8990 converter .structure (unstructured , cl )
9091
9192
@@ -100,7 +101,7 @@ def test_forbid_extra_keys_defaults(attr_and_vals):
100101 inst = cl ()
101102 unstructured = converter .unstructure (inst )
102103 unstructured ["aa" ] = unstructured .pop ("a" )
103- with pytest .raises (Exception ):
104+ with pytest .raises (ForbiddenExtraKeyError ):
104105 converter .structure (unstructured , cl )
105106
106107
@@ -120,7 +121,7 @@ class A:
120121 converter .structure (unstructured , A )
121122 # if we break it in the subclass, we need it to raise
122123 unstructured ["c" ]["aa" ] = 5
123- with pytest .raises (Exception ):
124+ with pytest .raises (ForbiddenExtraKeyError ):
124125 converter .structure (unstructured , A )
125126 # we can "fix" that by disabling forbid_extra_keys on the subclass
126127 hook = make_dict_structure_fn (
@@ -130,7 +131,7 @@ class A:
130131 converter .structure (unstructured , A )
131132 # but we should still raise at the top level
132133 unstructured ["b" ] = 6
133- with pytest .raises (Exception ):
134+ with pytest .raises (ForbiddenExtraKeyError ):
134135 converter .structure (unstructured , A )
135136
136137
0 commit comments