5555NO_MSGSPEC : Final = python_implementation () == "PyPy"
5656NO_ORJSON : Final = python_implementation () == "PyPy"
5757
58+ try :
59+ __import__ ("cbor2" )
60+ except ImportError :
61+ NO_CBOR2 = True
62+ else :
63+ NO_CBOR2 = False
64+
5865
5966@define
6067class A :
@@ -832,6 +839,7 @@ def test_tomllib_converter_unstruct_collection_overrides(everything: Everything)
832839 assert raw ["a_frozenset" ] == sorted (raw ["a_frozenset" ])
833840
834841
842+ @pytest .mark .skipif (NO_CBOR2 , reason = "cbor2 not available" )
835843@given (everythings (min_int = - 9223372036854775808 , max_int = 18446744073709551615 ))
836844def test_cbor2 (everything : Everything ):
837845 from cbor2 import dumps as cbor2_dumps
@@ -844,6 +852,7 @@ def test_cbor2(everything: Everything):
844852 assert converter .structure (cbor2_loads (raw ), Everything ) == everything
845853
846854
855+ @pytest .mark .skipif (NO_CBOR2 , reason = "cbor2 not available" )
847856@given (everythings (min_int = - 9223372036854775808 , max_int = 18446744073709551615 ))
848857def test_cbor2_converter (everything : Everything ):
849858 from cattrs .preconf .cbor2 import make_converter as cbor2_make_converter
@@ -853,6 +862,7 @@ def test_cbor2_converter(everything: Everything):
853862 assert converter .loads (raw , Everything ) == everything
854863
855864
865+ @pytest .mark .skipif (NO_CBOR2 , reason = "cbor2 not available" )
856866@given (everythings (min_int = - 9223372036854775808 , max_int = 18446744073709551615 ))
857867def test_cbor2_converter_unstruct_collection_overrides (everything : Everything ):
858868 from cattrs .preconf .cbor2 import make_converter as cbor2_make_converter
@@ -864,6 +874,7 @@ def test_cbor2_converter_unstruct_collection_overrides(everything: Everything):
864874 assert raw ["a_frozenset" ] == sorted (raw ["a_frozenset" ])
865875
866876
877+ @pytest .mark .skipif (NO_CBOR2 , reason = "cbor2 not available" )
867878@given (union_and_val = native_unions (include_datetimes = False ), detailed_validation = ...)
868879def test_cbor2_unions (union_and_val : tuple , detailed_validation : bool ):
869880 """Native union passthrough works."""
@@ -875,6 +886,7 @@ def test_cbor2_unions(union_and_val: tuple, detailed_validation: bool):
875886 assert converter .structure (val , type ) == val
876887
877888
889+ @pytest .mark .skipif (NO_CBOR2 , reason = "cbor2 not available" )
878890def test_cbor2_native_enums ():
879891 """Bare, string and int enums are handled correctly."""
880892
@@ -893,6 +905,7 @@ def test_cbor2_native_enums():
893905 )
894906
895907
908+ @pytest .mark .skipif (NO_CBOR2 , reason = "cbor2 not available" )
896909def test_cbor2_efficient_enum ():
897910 """`str` and `int` enums are handled efficiently."""
898911 from cattrs .preconf .cbor2 import make_converter as cbor2_make_converter
@@ -996,6 +1009,7 @@ def test_literal_dicts(converter_factory: Callable[[], Converter]):
9961009 assert converter .unstructure ({"a" : 1 }, Dict [Literal ["a" ], int ]) == {"a" : 1 }
9971010
9981011
1012+ @pytest .mark .skipif (NO_CBOR2 , reason = "cbor2 not available" )
9991013def test_literal_dicts_cbor2 ():
10001014 """Dicts with keys that aren't subclasses of `type` work."""
10011015 from cattrs .preconf .cbor2 import make_converter as cbor2_make_converter
0 commit comments